MainActivity is as follows:
Package cn. c; import android. app. activity; import android. OS. bundle; import android. view. motionEvent; import android. view. view; import android. view. view. onTouchListener; import android. widget. imageView;/*** Requirement Description: * When you click ImageView to load a network image, the image will be clicked. * similar to local image operations * implementation method: * implement OnTouchListener () for ImageView to process its Click Event * change the Alpha of the ImageView control when clicking the event * Note: * return true in onTouch; otherwise, you can only listen to the press * and cannot listen to the push */public class MainActivity extends Activity {private ImageView mImageView; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mImageView = (ImageView) findViewById (R. id. imageView); // the process of obtaining the network image, omitting // mImageView. setImageBitmap (bitmap from network); mImageView. setOnTouchListener (new TouchListenerImpl ();} private class TouchListenerImpl implements OnTouchListener {public boolean onTouch (View v, MotionEvent event) {ImageView imageView = (ImageView) v; // press if (event. getAction () = MotionEvent. ACTION_DOWN) {System. out. println ("down"); imageView. setAlpha (0); imageView. invalidate ();} // lift if (event. getAction () = MotionEvent. ACTION_UP | event. getAction () = MotionEvent. ACTION_CANCEL) {System. out. println ("up"); imageView. setAlpha (200); imageView. invalidate () ;}return true ;}}}
Main. xml is as follows:
<RelativeLayout 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"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "ImageView: network images are loaded. When you click ImageView, click images. operations similar to local images "android: layout_alignParentTop =" true "android: layout_centerHorizontal =" true "/> <ImageView android: id =" @ + id/imageView "android: layout_width = "80dip" android: layout_height = "80dip" android: src = "@ drawable/ic_launcher" android: layout_centerInParent = "true"/> </RelativeLayout>