This is an example from the crazy android handout. It is to use the listener to get the coordinates of the finger, and then draw an image based on the coordinates. (There are some problems with the rendering method here, so let's take a look .)
First, the layout file (two imageviews)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView01_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="Large Text"/> <ImageView android:id="@+id/imageView01_id" android:layout_width="match_parent" android:layout_height="300dp" android:src="@drawable/kale" android:scaleType="fitXY"/> <ImageView android:id="@+id/imageView02_id" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/kale" android:scaleType="fitXY"/> </LinearLayout>
Mainactivity. Java
Package COM. kale. imageview02; import android. app. activity; import android. graphics. bitmap; import android. graphics. drawable. bitmapdrawable; import android. OS. bundle; import android. view. motionevent; import android. view. view; import android. view. view. ontouchlistener; import android. widget. imageview; import android. widget. textview; public class mainactivity extends activity {imageview iv01, iv02; textview TV; @ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); viewinit ();} public void viewinit () {iv01 = (imageview) findviewbyid (R. id. imageview01_id); iv02 = (imageview) findviewbyid (R. id. imageview02_id); TV = (textview) findviewbyid (R. id. textview01_id); iv01.setontouchlistener (New ontouchlistener () {@ override public Boolean ontouch (view arg0, motionevent event) {If (event. getaction () = motionevent. action_move) {TV. settext ("x cursor =" + event. getx () + "y cursor =" + event. gety ();} If (event. getaction () = motionevent. action_down) {// obtain bitmapdrawable object bitmapdrawable = (bitmapdrawable) iv01.getdrawable (); // obtain Bitmap bitmap = bitmapdrawable. getbitmap (); // sets the bitmap ratio to double scale = bitmap. getwidth ()/320.0; // defines the starting position of the vertex int x = (INT) (event. getx () * scale); int y = (INT) (event. gety () * scale); If (x + 120> bitmap. getwidth () {x = bitmap. getwidth ()-120;} If (Y + 120> bitmap. getheight () {Y = bitmap. getheight ()-120;} // displays the specified region of the video clip, iv02.setimagebitmap (bitmap. createbitmap (bitmap, X, Y, 120,120);} // If the parameter is set to false, return true will not be displayed for moving the animation ;}});}}