photoview与drawerlayout滑动冲突-ArrayIndexOutOfBounds

在做软件开发的时候,我在其中一个drawerlayout布局中放置了一个photoview控件,支持拉伸缩放的控件,但是在运行的时候,当我放大照片或者缩小图片时,程序会因异常而停止。查看错误日志显示 java.lang.ArrayIndexOutOfBounds,经过查询资料,我重写了drawlayout的onInterceptTouchEvent方法,详细代码如下

[java]  view plain  copy
  1. public class ExtendLayout extends DrawerLayout {  
  2.     public ExtendLayout(Context context) {  
  3.         super(context);  
  4.     }  
  5.   
  6.     public ExtendLayout(Context context, AttributeSet attrs) {  
  7.         super(context, attrs);  
  8.     }  
  9.   
  10.     public ExtendLayout(Context context, AttributeSet attrs, int defStyle) {  
  11.         super(context, attrs, defStyle);  
  12.     }  
  13.   
  14.     @Override  
  15.     public boolean onInterceptTouchEvent(MotionEvent ev) {  
  16.         try {  
  17.             return super.onInterceptTouchEvent(ev);  
  18.         }  
  19.         catch (IllegalArgumentException e){  
  20.             e.printStackTrace();  
  21.             return false;  
  22.         }  
  23.         catch (ArrayIndexOutOfBoundsException e){  
  24.             e.printStackTrace();  
  25.             Log.e("CCC","拦截了");  
  26.             return false;  
  27.         }  
  28.     }  
  29. }  
然后使用这个ExtendLayout代替原来使用的DrawerLayout,重新运行程序,在拉伸或缩放图片中,成功打印了“拦截了”这行日志,说明滑动事件的异常被ExtendLayout捕获了并且不拦截该事件,事件下发给子view,也就是photoview,因此,异常解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值