【发布时间】:2017-05-18 07:29:02
【问题描述】:
我有一个问题。我应该如何停止在android中滚动列表视图,因为我只想用两个名为“up”和“down”的按钮滚动 提前致谢。
【问题讨论】:
-
在提问前考虑搜索。 stackoverflow.com/questions/18613844/…
我有一个问题。我应该如何停止在android中滚动列表视图,因为我只想用两个名为“up”和“down”的按钮滚动 提前致谢。
【问题讨论】:
您需要继承您的 ListView 并覆盖以下方法:
@Override public boolean dispatchTouchEvent(MotionEvent e) {
if(e.getAction()==MotionEvent.ACTION_MOVE) {
return true;
}
return super.dispatchTouchEvent(e);
}
【讨论】:
如果您不需要从 ListView 中选择行,您可以使用:
listview.setEnabled(false)
否则,你需要重写 dispatchTouchEvent :
@Override public boolean dispatchTouchEvent(MotionEvent e) {
if(e.getAction()==MotionEvent.ACTION_MOVE) {
return true;
}
return super.dispatchTouchEvent(e);
}
然后,要实现您的按钮,您可以使用:
listview.smoothScrollToPosition(position);
【讨论】:
可以通过列表视图的属性来管理滚动功能
// to stop the scrolling of list view
listView.smoothScrollBy(0, 0);
//to move to the specified specific position in listview
listView.setSelection(listItemposition)
【讨论】: