在项目中遇到使用gallery实现左右滑屏的时候,发现一个问题就是滑动一次gallery会滑过好几张图片,到网上查了些资料,找到了解决方法就是继承gallery,然后重写onFliping方法让其返回false.代码如下:
package com.gallery;
public class MyGallery extends Gallery{
public GalleryFlow(Context context) {
super(context);
}
public GalleryFlow(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GalleryFlow(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
return false;
}
}
注:在xml中定义gallery时,引用的是<com.gallery.MyGallery>