google搜索到国外网站 http://stackoverflow.com/questions/6919292/pointerindex-out-of-range-android-multitouch有介绍。通过捕捉异常方式。
解决步骤:1.自定义viewpager
2.重写onTouchEvent和onInterceptTouchEvent方法
例子:public class MyViewPager extends ViewPager {
public ViewPagerFixed(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
return false;
}
}
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<cn.ypark.yuezhu.View.myViewpager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />