photoview与drawerlayout滑动冲突-ArrayIndexOutOfBounds
2016-04-30 17:17
796 查看
在做广外小助手的时候,为了提供校历查看功能我在其中一个fragment中放置了一个photoview控件,因为校历的图片比较大而手机屏幕没有那么大,所以要使用这个支持拉伸缩放的控件,但是在运行的时候,当我放大照片或者缩小图片时,程序会因异常而停止。查看错误日志显示 java.lang.ArrayIndexOutOfBounds,经过查询资料,我重写了drawlayout的onInterceptTouchEvent方法,详细代码如下
public class ExtendLayout extends DrawerLayout {
public ExtendLayout(Context context) {
super(context);
}
public ExtendLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExtendLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
}
catch (IllegalArgumentException e){
e.printStackTrace();
return false;
}
catch (ArrayIndexOutOfBoundsException e){
e.printStackTrace();
Log.e("CCC","拦截了");
return false;
}
}
}然后使用这个ExtendLayout代替原来使用的DrawerLayout,重新运行程序,在拉伸或缩放图片中,成功打印了“拦截了”这行日志,说明滑动事件的异常被ExtendLayout捕获了并且不拦截该事件,事件下发给子view,也就是photoview,因此,异常解决。
public class ExtendLayout extends DrawerLayout {
public ExtendLayout(Context context) {
super(context);
}
public ExtendLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExtendLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
}
catch (IllegalArgumentException e){
e.printStackTrace();
return false;
}
catch (ArrayIndexOutOfBoundsException e){
e.printStackTrace();
Log.e("CCC","拦截了");
return false;
}
}
}然后使用这个ExtendLayout代替原来使用的DrawerLayout,重新运行程序,在拉伸或缩放图片中,成功打印了“拦截了”这行日志,说明滑动事件的异常被ExtendLayout捕获了并且不拦截该事件,事件下发给子view,也就是photoview,因此,异常解决。
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories