列表视图每一行的滑动检测

发布于 2024-11-19 03:12:45 字数 356 浏览 6 评论 0原文

我的 SD 卡中有一个视频列表。此时,我只需要帮助为列表视图中的每一行创建手势或滑动检测。感谢 stackoverflow 网格布局上的 Fling 手势检测 上的这个问题,我在列表视图上实现了手势。现在,它可以轻松检测用户何时向右或向左滑动。但这个手势是针对整个列表视图的。我只是想知道如何对各个行实现这种滑动检测。例如,应用程序现在制作一个打印“向右滑动”、“向左滑动”的吐司。我只是想让它像“在第 1 行上向右滑动”、“在第 3 行上向左滑动”等。我希望我的问题很清楚。

期待一些有用的回复。 谢谢

I have a list of videos located in the sd-card. At this point, I just need help in creating gestures or swipe detection for each row in the list view. Thanks to this question at stackoverflow Fling gesture detection on grid layout, I implemented the gesture on the listview. It now easily detects when the user swipes in the right direction or left direction. But this gesture is for the entire listview. I just want to know how can I implement this swipe detection for individual rows. For example, the application now makes a toast that prints "Right Swipe", "Left Swipe". I just want to make it like "Right Swipe on row no 1", "Left Swipe on Row no 3" etc.. I hope my question was clear.

Looking forward to some helpful replies.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

驱逐舰岛风号 2024-11-26 03:12:45

查看这个答案并使用pointToPosition 方法onFling 事件

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    try {
        Toast.makeText( listAdapter.getItem( listView.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY())).toString());
        return super.onFling();
    } catch( Exception e ) {
        // do nothing
    }
}

Take a look into this answer and use pointToPosition method inside onFling Event

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    try {
        Toast.makeText( listAdapter.getItem( listView.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY())).toString());
        return super.onFling();
    } catch( Exception e ) {
        // do nothing
    }
}
裸钻 2024-11-26 03:12:45

我在解决方案中使用了逐项方法 - 请查看此处
我的滑动检测代码可能与标准滑动检测有点不同,但它非常适合我。我正在使用附加标签来获取项目相关数据。
希望这会有所帮助,但如果您确实有一些问题,请告诉我,我会尝试更详细地解释。

I'm using the per item approach in my solution - take a look here
My swipe detection code might be a bit different from standard swipe detection but it works perfectly for me. And I'm using attached tags to get the item related data.
Hope that helps, but if you do have some questions just let me know and I'll try to explain in more detail.

随心而道 2024-11-26 03:12:45

根据我的意见,该项目使用布尔值,当该项目被触摸时设置为 true,使用 onTouchListener,

ListItem.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            click=true;
            return click;


        }

    });`

那么您可以覆盖它:

 @Override
public boolean dispatchTouchEvent(MotionEvent ev){
super.dispatchTouchEvent(ev);
Log.v("Inside", "=====Dispatch Event===");
if(click){
    Log.v("Inside", "=====Dispatch Event=T==");
    click=false;
     return gestureDetector.onTouchEvent(ev);

}else{
    return false;
}

}

As Per My Opinion is Use Boolean for the item,When that item is touched set as true,Using onTouchListener,

ListItem.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            click=true;
            return click;


        }

    });`

Then You Can Override This:

 @Override
public boolean dispatchTouchEvent(MotionEvent ev){
super.dispatchTouchEvent(ev);
Log.v("Inside", "=====Dispatch Event===");
if(click){
    Log.v("Inside", "=====Dispatch Event=T==");
    click=false;
     return gestureDetector.onTouchEvent(ev);

}else{
    return false;
}

}
懒猫 2024-11-26 03:12:45

我认为您正在寻找的是 SwipeView (或者甚至可能是 ViewFlow)而不是标准的 Android 手势检测。

I think what you're looking for is SwipeView (or perhaps even ViewFlow) rather than standard Android gesture detection.

一花一树开 2024-11-26 03:12:45

这个问题已经很老了,但值得庆幸的是,Jake Wharton 在这里反向移植了一些为 ICS 发布的代码;这应该允许您滑动各个行: https://github.com/JakeWharton/SwipeToDismissNOA

This question is old, but by now thankfully Jake Wharton backported some code released for ICS here; this should allow you to swipe individual rows: https://github.com/JakeWharton/SwipeToDismissNOA

李白 2024-11-26 03:12:45

我们在此处实现了每行滑动检测,以显示操作并消除项目 https://github.com/47deg/android-滑动列表视图。我希望它有帮助

We implemented swipe detection per row for revealing actions and dismissing items here https://github.com/47deg/android-swipelistview . I hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文