本文实例讲述了Android编程实现GridView控件点击图片变暗效果的方法。分享给大家供大家参考,具体如下:
创新互联建站是创新、创意、研发型一体的综合型网站建设公司,自成立以来公司不断探索创新,始终坚持为客户提供满意周到的服务,在本地打下了良好的口碑,在过去的10余年时间我们累计服务了上千家以及全国政企客户,如成都除甲醛等企业单位,完善的项目管理流程,严格把控项目进度与质量监控加上过硬的技术实力获得客户的一致赞誉。@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); grid = (GridView) findViewById(R.id.grid); grid.setAdapter(new GridAdapter()); grid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Toast.makeText(MainActivity.this, "ddd", 1000).show(); } }); } class GridAdapter extends BaseAdapter { @Override public int getCount() { return imgs.length; } @Override public Object getItem(int arg0) { return arg0; } @Override public long getItemId(int arg0) { return arg0; } @Override public View getView(int arg0, View view, ViewGroup arg2) { if (view == null) { holder = new ViewHolder(); 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); return view; } class ViewHolder { ImageView view; } public OnTouchListener onTouchListener = new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: changeLight((ImageView) view, 0); // onclick break; case MotionEvent.ACTION_DOWN: changeLight((ImageView) view, -80); break; case MotionEvent.ACTION_MOVE: // changeLight(view, 0); break; case MotionEvent.ACTION_CANCEL: changeLight((ImageView) view, 0); break; default: break; } return true; } }; } private void changeLight(ImageView imageview, int brightness) { ColorMatrix matrix = new ColorMatrix(); 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(new ColorMatrixColorFilter(matrix)); }
本文名称:Android编程实现GridView控件点击图片变暗效果的方法-创新互联
网站网址:https://www.cdcxhl.com/article38/eejpp.html
成都网站建设公司_创新互联,为您提供网站排名、移动网站建设、云服务器、服务器托管、企业建站、建站公司
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联