@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