Android 开源项目PhotoView遇到问题

PhotoView 是一款扩展自Android ImageView ,支持通过单点/多点触摸来进行图片缩放的智能控件。


良好特性:

  • 支持单点/多点触摸,即时缩放图片;
  • 支持平滑滚动;
  • 在滑动父控件下能够运行良好;(例如:ViewPager)
  • 当用户的触点改变是可以触发通知
当和ViewPager嵌套使用的时候,放大缩小会出现一个异常: IllegalArgumentException: pointerIndex out of range.
这是Android ViewPager的一个BUG
这里可以更改为 HackyViewPager ,它是继承的ViewPaer.

PhotoView的GIT仓库提供的例子也已经改了。

链接:https://github.com/chrisbanes/PhotoView

HackyViewPager源码如下:

**
 * Hacky fix for Issue #4 and
 * http://code.google.com/p/android/issues/detail?id=18990
 * 
 * ScaleGestureDetector seems to mess up the touch events, which means that
 * ViewGroups which make use of onInterceptTouchEvent throw a lot of
 * IllegalArgumentException: pointerIndex out of range.
 * 
 * There's not much I can do in my code for now, but we can mask the result by
 * just catching the problem and ignoring it.
 * 
 * @author Chris Banes
 */
public class HackyViewPager extends ViewPager {

	private static final String TAG = "HackyViewPager";

	public HackyViewPager(Context context) {
		super(context);
	}

	public HackyViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		try {
			return super.onInterceptTouchEvent(ev);
		} catch (IllegalArgumentException e) {

			Log.e(TAG, "hacky viewpager error1");
			return false;
		} catch (ArrayIndexOutOfBoundsException e) {

			Log.e(TAG, "hacky viewpager error2");
			return false;
		}
	}

}





你可能感兴趣的:(android,viewpager,开源项目,photoview)