ListView的水平一扔手势 [英] ListView Horizontal Fling Gesture

查看:119
本文介绍了ListView的水平一扔手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示给定日期的条目列表视图。有列表视图上面的按钮,用户可以增加/减少的日期。一切正常。什么我希望做的是取代那些按钮,并让用户刷卡左/右增加/减少的日期。

I have a listview that displays entries for a given date. There are buttons above the listview that allow you to increase/decrease the date. Everything works. What I'm looking to do is replace those buttons and have the user swipe right/left to increase/decrease the date.

什么是去了解这一点的最好方法是什么?我不在乎什么项目被偷走,经常会出现在列表视图中给定日期没有任何项目,只要你将它发生在列表视图区域。我必须上的项目已经点击和longclick听众。

What's the best way to go about this? I don't care what item is swiped, often there will be no items in the listview for a given date, just as long as it happens on the listview area. I do have click and longclick listeners on the items already.

推荐答案

只需实现OnGestureListener。

Just implement the OnGestureListener.

public class MyListActivity extends ListActivity implements OnGestureListener

使用一个GestureDetector

Use a GestureDetector

GestureDetector detector = new GestureDetector(this, this);

传递列表的触摸事件的GestureDetector

Pass the touch event of the list to the GestureDetector

listView.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View view, MotionEvent e) {
        detector.onTouchEvent(e);
        return false;
    }
});

和最终使用一扔方法来检测一个手势。可以使用速度值来检测运动的方向。

And finally use the fling method to detect a gesture. You can use the velocity values to detect the direction of the movement.

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {}

这篇关于ListView的水平一扔手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆