"Android" adds a shadow effect to ImageView (modal effect)

Source: Internet
Author: User

For example, in the adapter:

To set the listener:

Viewholder.g_imageview_item.setOnTouchListener (Ontouchlistener);

View.ontouchlistener Ontouchlistener = new Ontouchlistener () {@Overridepublic Boolean onTouch (View V, motionevent event) {ImageView = (ImageView) v;if (event.getaction () = = Motionevent.action_down) {imageview.setimagedrawable (g_ Context.getresources (). getdrawable (R.drawable.moreapp_filter));//Mask Imageview.invalidate ();} return false;}};

Then clear the ImageView in the entry click event:

Convertview.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {G_onclick.onclick ( position, channel); if (ImageView! = null) {imageview.setimagedrawable (null);}});

The layout of the G_imageview_item is as follows:

Where @drawable/moreapp_filter is a shadow picture

<imageview android:id= "@+id/moreitem_imageview_icon" android:layout_width= "54dip" Android:layout_h eight= "54dip" android:src= "@drawable/moreapp_filter" android:scaletype= "Centercrop" Android:layout_ce Nterhorizontal= "true" android:layout_marginbottom= "6dip" android:layout_margintop= "20dip"/>

In addition, there is a relatively good article:

ImageView Shadow Effect

Or:

View.ontouchlistener Ontouchlistener =new View.ontouchlistener () {@Override public boolean onTouch (View V, motionevent Event) {ImageView imgview= (ImageView) v; if (event.getaction () ==motionevent.action_down) {Imgview.setalpha (0xDF); Imgview.invalidate (); } else if (Event.getaction () ==motionevent.action_up| | Event.getaction () ==motionevent.action_cancel) {Imgview.setalpha (0xFF); Imgview.invalidate ();} return false; }};

But the above effect is not very good.

"Android" adds a shadow effect to ImageView (modal effect)

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.