Android allows you to click non-local images.

Source: Internet
Author: User

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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.