import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;
public class GuideGallery extends Gallery {
public GuideGallery(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public GuideGallery(Context context,AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public GuideGallery(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
int kEvent;
if(isScrollingLeft(e1, e2)){ //Check if scrolling left
kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
}
else{ //Otherwise scrolling right
kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
}
onKeyDown(kEvent, null);
return true;
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
return e2.getX() > e1.getX();
}
}
android Gallery做图片滚动,每次滑动翻一页
最新推荐文章于 2025-12-03 12:28:21 发布
本文介绍了一个定制的GuideGallery控件,该控件继承自Android的Gallery类,并重写了onFling方法以实现通过触摸屏滑动触发方向键事件的功能。当用户从右向左滑动时,模拟发送DPAD_LEFT方向键事件;反之,则发送DPAD_RIGHT方向键事件。
166

被折叠的 条评论
为什么被折叠?



