[英]Stop scrolling in a listview when user touches the list - android
I have a list view that contains about 30 items. 我有一个包含大约30个项目的列表视图。 When I scroll it down it just goes to the very bottom of the list and does not stop when the user touches the list.
当我向下滚动它时,它只是到达列表的最底部,并且当用户触摸列表时不会停止。
Is there a method to stop the scrolling when the list view is touched and at the same time user should be able to navigate using onItemClick(already handled).. 有没有一种方法可以在触摸列表视图时停止滚动,并且同时用户应该可以使用onItemClick(已处理)进行导航。
Thank you! 谢谢!
Use smoothScrollBy
. 使用
smoothScrollBy
。
@Override
public boolean onTouchEvent(MotionEvent ev)
{
switch (ev.getAction())
{
case MotionEvent.ACTION_UP:
this.smoothScrollBy(0, 0);
break;
}
return super.onTouchEvent(ev);
}
By referring to Nitin Gupta's answer, I came up with my own: 通过参考Nitin Gupta的答案,我想出了自己的答案:
public class OnTouchListenr implements OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
businessResultListView.smoothScrollBy(0, 0);
return true;
}
return false;
}
}
Then I set the OnTouchListener on the list view like this: 然后我在列表视图上设置OnTouchListener,如下所示:
businessResultListView.setOnTouchListener(new OnTouchListenr());
Override dispatchTouchEvent in your Listview 覆盖ListView中的dispatchTouchEvent
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
if(ev.getAction()==MotionEvent.ACTION_MOVE){
return true;
}return super.dispatchTouchEvent(ev);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.