如何停止列表视图的滚动以及如何在Android中使用按钮滚动列表视图?
我有个问题。在android中,我应该如何停止列表视图的滚动,因为我只想用两个名为“向上”和“向下”的按钮滚动如何停止列表视图的滚动以及如何在Android中使用按钮滚动列表视图?,android,listview,scroll,Android,Listview,Scroll,我有个问题。在android中,我应该如何停止列表视图的滚动,因为我只想用两个名为“向上”和“向下”的按钮滚动 提前感谢。您需要对ListView进行子类化,并覆盖以下方法: @Override public boolean dispatchTouchEvent(MotionEvent e) { if(e.getAction()==MotionEvent.ACTION_MOVE) { return true; } return super.dispatch
提前感谢。您需要对ListView进行子类化,并覆盖以下方法:
@Override public boolean dispatchTouchEvent(MotionEvent e) {
if(e.getAction()==MotionEvent.ACTION_MOVE) {
return true;
}
return super.dispatchTouchEvent(e);
}
可以按列表视图的属性处理以管理滚动功能
// to stop the scrolling of list view
listView.smoothScrollBy(0, 0);
//to move to the specified specific position in listview
listView.setSelection(listItemposition)
如果不需要从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);
在提问之前考虑一下搜索。