之前的问题了,记录一下,即在Gallery中,横滑滑到最后一张,再滑时,弹出提示框提示已经是最后一张。注意:不是一滑到最后一张就出提示。现在实现的方法没有想象的那么复杂,但是之前没想到的时候就是没想到啊。
public class HotPictureGallery extends Gallery {
private int sign = 0;//就是这个变量啦
public HotPictureGallery(Context paramContext, AttributeSet paramAttributeSet) {
// TODO Auto-generated constructor stub
super(paramContext, paramAttributeSet);
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
// TODO Auto-generated constructor stub
return e2.getX() > e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// TODO Auto-generated constructor stub
int kEvent;
if(isScrollingLeft(e1, e2)){
//Check if scrolling left
kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
sign = 0;
} else{
//Otherwise scrolling right
kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
if (HotActivity.gallery.getLastVisiblePosition() + 1 == HotActivity.gallery.getCount()) {
if(sign != 0){
HotPictureDetailActivity.builder.show();
}
sign = 1;
}
}
onKeyDown(kEvent, null);
return true;
}
}
public class HotPictureGallery extends Gallery {
private int sign = 0;//就是这个变量啦
public HotPictureGallery(Context paramContext, AttributeSet paramAttributeSet) {
// TODO Auto-generated constructor stub
super(paramContext, paramAttributeSet);
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
// TODO Auto-generated constructor stub
return e2.getX() > e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// TODO Auto-generated constructor stub
int kEvent;
if(isScrollingLeft(e1, e2)){
//Check if scrolling left
kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
sign = 0;
} else{
//Otherwise scrolling right
kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
if (HotActivity.gallery.getLastVisiblePosition() + 1 == HotActivity.gallery.getCount()) {
if(sign != 0){
HotPictureDetailActivity.builder.show();
}
sign = 1;
}
}
onKeyDown(kEvent, null);
return true;
}
}