Android 多个ImageView图片层叠透明区域点击事件穿透
来源:互联网 发布:dnf安徒恩优化补丁 编辑:程序博客网 时间:2024/05/23 12:55
经常用到多个透明图片层叠,但又需要获取不同图片的点击事件,本文实现图片透明区域穿透点击事件。
实现人体各个部位点击
内部类
private class MyOnTouchListener implements OnTouchListener {private ImageView touchImageView;private Bitmap touchBitmap;private int normal_iv;private int press_iv;public MyOnTouchListener(ImageView touchImageView, Bitmap touchBitmap,int normal_iv, int press_iv) {super();this.touchImageView = touchImageView;this.touchBitmap = touchBitmap;this.normal_iv = normal_iv;this.press_iv = press_iv;}@Overridepublic boolean onTouch(View v, MotionEvent event) {LogUtils.i(TAG, "onTouch。。。");switch (event.getAction()) {case MotionEvent.ACTION_DOWN:LogUtils.i(TAG, "ACTION_DOWN ");downOrMove(event);break;case MotionEvent.ACTION_MOVE:LogUtils.i(TAG, "ACTION_MOVE ");downOrMove(event);break;case MotionEvent.ACTION_UP:LogUtils.i(TAG, "ACTION_UP ");touchImageView.setImageResource(normal_iv);break;default:break;} return false;}private void downOrMove(MotionEvent event) {Matrix inverse = new Matrix();touchImageView.getImageMatrix().invert(inverse);float[] touchPoint = new float[] { event.getX(), event.getY() };inverse.mapPoints(touchPoint);int xCoord = Integer.valueOf((int) touchPoint[0]);int yCoord = Integer.valueOf((int) touchPoint[1]);if((xCoord >= 0 && xCoord < touchBitmap.getWidth()) && (yCoord >=0 && yCoord < touchBitmap.getHeight())) {if (touchBitmap.getPixel(xCoord, yCoord) == 0) {touchImageView.setImageResource(normal_iv);} else {touchImageView.setImageResource(press_iv);}}}}activity中实现
@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:LogUtils.i(TAG, "Activity ACTION_DOWN ");break;case MotionEvent.ACTION_MOVE:LogUtils.i(TAG, "Activity ACTION_MOVE ");break;case MotionEvent.ACTION_UP:LogUtils.i(TAG, "Activity ACTION_UP ");cancelAllIv();break;default:break;}return super.onTouchEvent(event);}
0 0
- Android 多个ImageView图片层叠透明区域点击事件穿透
- Android 多个ImageView图片层叠透明区域点击事件穿透
- IOS 多个ImageView图片层叠透明区域点击事件穿透
- Android ImageView图片透明区域不响应点击事件,不规则图片透明区域响应点击事件
- Android ImageView包含透明区域的图片点击事件处理
- iOS实现UIImageView透明区域点击事件穿透
- iOS实现UIImageView透明区域点击事件穿透
- iOS实现UIImageView透明区域点击事件穿透
- iOS实现UIImageView透明区域点击事件穿透
- iOS实现UIImageView透明区域点击事件穿透
- iOS 实现 UIImageView 透明区域点击事件穿透
- iOS实现UIImageView透明区域点击事件穿透
- iOS实现UIImageView透明区域点击事件穿透(OC&swift)
- android点击事件穿透
- Android同一个TextView里响应多个区域点击事件
- 透明控件点击事件穿透的解决办法
- Android中不规则图片按钮透明区域的点击效果
- Android DrawerLayout 点击事件穿透
- 简单翻页动画实现
- 去除asp.net 2.0的会话cookie ASP.NET_SessionId 的httponly属性
- lrj OMG
- sleep 函数的使用
- OutputCapture
- Android 多个ImageView图片层叠透明区域点击事件穿透
- IOS之Info.plist文件简介
- Python中re(正则表达式)模块学习
- GRE写作必备句型
- Linux的inode的理解
- 贪吃蛇之一维数组实现
- 凌科芯安LKT与目前市场上几种安全加密芯片的对比
- 2012年5月SAT香港真题解析
- 欢迎使用CSDN-markdown编辑器