当前位置:编程学习 > wap >>

关于android控件上手势的问题

--------------------编程问答-------------------- class GVIntGestureListener implements OnGestureListener,OnTouchListener {
private GestureDetector mGestureDetector;
public GVIntGestureListener() {
mGestureDetector = new GestureDetector(mLauncher,this);
mGestureDetector.setIsLongpressEnabled(false);  
}
public boolean onDown(MotionEvent e) {
Log.i("Down","Down");
return false;
}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.i("onFling","onFling");
if(Math.abs(velocityX)>Math.abs(velocityY ) && mDragView==null && !mbIsDraging){
//当前滑动的子控件索引
int FlingChildIndex = pointToPosition((int) e2.getX(), (int) e2.getY());
TubiaoElementInfo tElement = new TubiaoElementInfo();

//最后一个元素为“添加”,不处理其滑动事件
if(FlingChildIndex!=INVALID_POSITION && FlingChildIndex < mAdapter.getCount() - 1){
tElement = (TubiaoElementInfo)mAdapter.getItem(FlingChildIndex);
View item = getChildAt(FlingChildIndex - getFirstVisiblePosition());
mDragger.startDrag(item, GridViewInterceptor.this, tElement, DragController.DRAG_ACTION_MOVE);
//在滑动开始后禁用GridViewInterceptor,这样它就不能接收到Touch操作
setEnabled(false);
mbIsDraging = true;
}
}
return true;
}

public void onLongPress(MotionEvent e) {
Log.i("onLongPress","onLongPress");
}

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.i("onScroll","distanceX"+distanceX+"distanceY"+distanceY);
if(Math.abs(distanceX)>Math.abs(distanceY) && mDragView==null && !mbIsDraging){
//当前滑动的子控件索引
int FlingChildIndex = pointToPosition((int) e2.getX(), (int) e2.getY());
TubiaoElementInfo tElement = new TubiaoElementInfo();

//最后一个元素为“添加”,不处理其滑动事件
if(FlingChildIndex!=INVALID_POSITION && FlingChildIndex < mAdapter.getCount() - 1){
tElement = (TubiaoElementInfo)mAdapter.getItem(FlingChildIndex);
ViewGroup item = (ViewGroup) getChildAt(FlingChildIndex - getFirstVisiblePosition());
mDragger.startDrag(item, GridViewInterceptor.this, tElement, DragController.DRAG_ACTION_MOVE);
//在滑动开始后禁用GridViewInterceptor,这样它就不能接收到Touch操作
setEnabled(false);
mbIsDraging = true;
}
}
return false;
}


补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,