Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何停止列表视图的滚动以及如何在Android中使用按钮滚动列表视图?_Android_Listview_Scroll - Fatal编程技术网

如何停止列表视图的滚动以及如何在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

我有个问题。在android中,我应该如何停止列表视图的滚动,因为我只想用两个名为“向上”和“向下”的按钮滚动
提前感谢。

您需要对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);

在提问之前考虑一下搜索。