Android GridView control click picture Darken Effect

Source: Internet
Author: User

@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); Grid=(GridView) Findviewbyid (R.id.grid); Grid.setadapter (NewGridadapter ()); Grid.setonitemclicklistener (NewOnitemclicklistener () {@Override Public voidOnitemclick (adapterview<?> arg0, View arg1,intArg2,LongArg3) {Toast.maketext (mainactivity). This, "ddd", 1000). Show (); }    });}classGridadapterextendsBaseadapter {@Override Public intGetCount () {returnimgs.length; } @Override PublicObject GetItem (intarg0) {        returnarg0; } @Override Public LongGetitemid (intarg0) {        returnarg0; } @Override PublicView GetView (intarg0, view view, ViewGroup arg2) {        if(View = =NULL) {Holder=NewViewholder (); View= Layoutinflater.from (mainactivity. This). Inflate (R.layout.imgs,NULL); Holder.view=(ImageView) View.findviewbyid (r.id.gridimg);        View.settag (holder); } Else{Holder=(Viewholder) View.gettag ();        } holder.view.setImageResource (imgs[arg0]);        Holder.view.setOnTouchListener (Ontouchlistener); returnview; }    classViewholder {ImageView view; }     PublicOntouchlistener Ontouchlistener =NewView.ontouchlistener () {@Override Public BooleanOnTouch (view view, Motionevent event) {Switch(Event.getaction ()) { CaseMotionEvent.ACTION_UP:changeLight (ImageView) view,0); //onclick                 Break;  CaseMotionEvent.ACTION_DOWN:changeLight (ImageView) view,-80);  Break;  CaseMotionevent.action_move://changelight (view, 0);                 Break;  CaseMotionEvent.ACTION_CANCEL:changeLight (ImageView) view,0);  Break; default:                 Break; }            return true; }    };}Private voidChangelight (ImageView ImageView,intbrightness) {ColorMatrix Matrix=NewColorMatrix (); Matrix.set (New float[] {1, 0, 0, 0, brightness, 0, 1, 0, 0, Brightness,0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 }); Imageview.setcolorfilter (Newcolormatrixcolorfilter (Matrix));}

Android GridView control click picture Darken 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.