如何在android setOnTouchListener android中获取列表项位置?

gRe*_*oRn 3 animation android listitem selector ontouchlistener

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

Nic*_*ckF 9

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

int pos = YOUR_LISTVIEW.pointToPosition((int) e1.getX(), (int) e1.getY());
Run Code Online (Sandbox Code Playgroud)
  • e1MotionEvent

  • 优秀的解决方案.我一直在等待像这样的人.作为魅力的工具.非常感谢. (2认同)