package com.aizheke.aizheked.widget;
import com.aizheke.aizheked.utils.AzkHelper;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;
public class OnebyoneGallery extends Gallery {
public OnebyoneGallery(Context context) {
super(context);
}
public OnebyoneGallery(Context context, AttributeSet attrs) {
super(context, attrs);
}
public OnebyoneGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
AzkHelper.showLog("gallery:" + e2.getX() + ", " + e1.getX());
return e2.getX() > e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
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;
}
}
posted on 2012-03-07 18:23
汪杰 阅读(266)
评论(0) 编辑 收藏 引用 所属分类:
Java