关于android控件上手势的问题

wu55uw 2012-05-17 09:39:45
我现在要做一个列表,列表竖直放在屏幕左侧,占屏幕1/4宽度,列表上的项要可以点击,长按,这个列表要可以上下滑动,而且向右拖动列表项的时候该项要可以马上被拖动,在拖动的同时要放大。请问这样的效果要用什么做比较好呢。
我现在用ListView实现了,点击长按上下滑动都没问题,用手势做的向右拖动判断总是不够灵敏,有什么好办法吗?
...全文
211 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wu55uw 2012-05-21
  • 打赏
  • 举报
回复
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;
}


80,493

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧