..
Android Smart Visitor

Place two multitouch custom view in a activity

May 21, 2011 | By Andro ID

In the exercise "Detect Multi touch on custom View", a customer view class with multitouch have been implemented. Now, we wil modify our layout to include two separated multitouch custom view, in different background color.



Tested on Nexus One running 2.2.1.


Keep no change on the MultiTouchView.java in "Detect Multi touch on custom View".

Modify main.xml to include two MultiTouchView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.exercise.AndroidTouch.MultiTouchView
android:id="@+id/mtv1"
android:layout_width="fill_parent"
android:layout_height="200dp"
/>
<com.exercise.AndroidTouch.MultiTouchView
android:id="@+id/mtv2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>


Modify AndroidTouch.java to set them in different background color.
package com.exercise.AndroidTouch;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;

public class AndroidTouch extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

MultiTouchView multiTouchView1 = (MultiTouchView)findViewById(R.id.mtv1);
MultiTouchView multiTouchView2 = (MultiTouchView)findViewById(R.id.mtv2);
multiTouchView1.setBackgroundColor(Color.WHITE);
multiTouchView2.setBackgroundColor(Color.GRAY);

}
}


Download the files.
addtomyyahoo4 Subscribe in NewsGator Online Add to My AOL
Subscribe with Bloglines Add to netvibes Add to Google