【问题标题】:how to get list item position in android setOnTouchListener android?如何在 android setOnTouchListener android 中获取列表项位置?
【发布时间】:2013-11-11 14:27:11
【问题描述】:

我正在 android 中实现 listview。我希望在按下 listview 项目时增加 listview 行的 layout_width 和 height。我正在使用 zoom_in 动画来缩放我保存在 anim 文件夹中的视图。但我无法在选择器中使用它,因为如果我把它放在选择器中,我不知道如何开始动画。 我尝试了另一种在适配器的getView中实现动画的方法。这里我需要从onTouchListener函数中获取我设置的选定视图的位置。但是现在我无法在onTouch函数中获取选定行的位置。我想知道如何在 onTouch 函数中获取行的位置?或者如何在适配器的 getView 函数中获取按下状态?提前致谢。

【问题讨论】:

    标签: android animation selector ontouchlistener listitem


    【解决方案1】:

    在您的触摸事件中,您可以获得触摸的 X、Y 坐标。
    ListView 有方法 pointToPosition

    int pos = YOUR_LISTVIEW.pointToPosition((int) e1.getX(), (int) e1.getY());
    
    • e1MotionEvent

    【讨论】:

    • 优秀的解决方案。我一直在等待这样的解决方案。就像魅力一样。非常感谢。
    • 不错的解决方案。谢谢
    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    相关资源
    最近更新 更多