使用PohtoView出现java.lang.IllegalArgumentException: pointerIndex out of range
来源:互联网 发布:使用java程序录音 编辑:程序博客网 时间:2024/06/05 17:45
使用PohtoView出现java.lang.IllegalArgumentException: pointerIndex out of range
- 我遇见的是在使用PhotoView的使用,在程序中动态的new一个ImageView出来,之后添加到ViewPager中。这时候运行程序如果使用手势对图片进行缩小,那么将会出来这个异常,在做多点触控放大缩小,操作自己所绘制的图形时发生这个异常,如果是操作图片的放大缩小多点触控不会出现这个错误
这个bug是Android系统原因
我的代码如下:
/** * 进行网络数据的请求和加载 */ private void loadData() { //TODO 进行网络数据的加载 if (picList != null) { for (int i = 0; i < picList.size(); i++) { ImageView imageView = new ImageView(this); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(params); EHttpUtil.bitmapUtils.display(imageView, picList.get(i)); PhotoViewAttacher mAttacher = new PhotoViewAttacher(imageView); mAttacher.setScaleType(ImageView.ScaleType.CENTER_CROP); mAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() { @Override public void onViewTap(View view, float x, float y) { ActivityTransationAnimation.finishActivityFullToZero(MainDesignerProductShowActivity.this); } }); mAttacher.setOnScaleChangeListener(new PhotoViewAttacher.OnScaleChangeListener() { @Override public void onScaleChange(float scaleFactor, float focusX, float focusY) { relativeLayout.setVisibility(View.GONE); } }); viewPagerList.add(imageView); } } }
之后运行就出现了这个错,但是我查了很多的资料,重写
1. onTouch()
2. InterceptTouchEvent()
对里面的super方法进行try/catch但是没有什么效果,我的程序还是崩溃,所以我就接着在stackoverflower 中查找解决方法,最后的话终于解决了。
具体方案如下:
import android.content.Context;import android.support.v4.view.ViewPager;import android.util.AttributeSet;import android.view.MotionEvent;/** * Author: blueZhang * Date: 2015/12/12 0012 * 163Email :bluezhang521@163.com * QEmail:bluezhang521@foxmail.com * QQ:2029379603 */public class MTouchViewPager extends ViewPager { public MTouchViewPager(Context context) { super(context); } public MTouchViewPager(Context context, AttributeSet attrs) { super(context, attrs); } private boolean mIsDisallowIntercept = false; @Override public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { // keep the info about if the innerViews do // requestDisallowInterceptTouchEvent mIsDisallowIntercept = disallowIntercept; super.requestDisallowInterceptTouchEvent(disallowIntercept); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { // the incorrect array size will only happen in the multi-touch // scenario. if (ev.getPointerCount() > 1 && mIsDisallowIntercept) { requestDisallowInterceptTouchEvent(false); boolean handled = super.dispatchTouchEvent(ev); requestDisallowInterceptTouchEvent(true); return handled; } else { return super.dispatchTouchEvent(ev); } }}
这样的话我的程序就能跑起来了,重写ViewPager 中的方法,这样就能直接吧ImageView放进ViewPager中进行缩放,缩放的过程中也能解决事件冲突的问题。
0 0
- 使用PohtoView出现java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- 解决java.lang.IllegalArgumentException: pointerIndex out of range的错误
- 解决java.lang.IllegalArgumentException: pointerIndex out of range的错误
- java.lang.IllegalArgumentException: pointerIndex out of range两种解决办法
- 图片缩放时java.lang.IllegalArgumentException: pointerIndex out of range
- Android java.lang.IllegalArgumentException: pointerIndex out of range
- 完美解决java.lang.IllegalArgumentException: pointerIndex out of range
- Android4.1上出现java.lang.IllegalArgumentException: pointerIndex out of range
- ViewPager中的图片多点触摸出现java.lang.IllegalArgumentException: pointerIndex out of range解决方案
- java.lang.IllegalArgumentException: pointerIndex out of range(ViewPager与PhotoView联合使用)
- Compare Strings
- Swift中的if语句使用where
- (转帖)SQL Server处理四亿三千万记录大型项目实录
- JSON使用JsonIgnoreAttribute,ErrorHandlingAttribute,DefaultValueAttribute
- USACO--Friday the Thirteenth
- 使用PohtoView出现java.lang.IllegalArgumentException: pointerIndex out of range
- Android Studio 快捷键
- sublime There are no packages available for installation错误
- 客户端提交内容的HTML内容过滤根据
- CPP 6th——类(7)
- View Frame、bounds、clipsToBounds、masksToBounds
- 我的2015---找寻真实的自己
- [java] 浅析ClassLoader
- Unity开发IOS游戏的优化建议