【问题标题】:How to Stop Scroll of list view and how to scroll list view with Button in Android? [duplicate]如何停止滚动列表视图以及如何在 Android 中使用 Button 滚动列表视图? [复制]
【发布时间】:2017-05-18 07:29:02
【问题描述】:

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

【问题讨论】:

标签: android listview scroll


【解决方案1】:

您需要继承您的 ListView 并覆盖以下方法:

@Override public boolean dispatchTouchEvent(MotionEvent e) {
   if(e.getAction()==MotionEvent.ACTION_MOVE) {
      return true;    
   }

   return super.dispatchTouchEvent(e); 
 }

【讨论】:

    【解决方案2】:

    如果您不需要从 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);
    

    【讨论】:

      【解决方案3】:

      可以通过列表视图的属性来管理滚动功能

      // to stop the scrolling of list view
      listView.smoothScrollBy(0, 0); 
      
      //to move to the specified specific position in listview
       listView.setSelection(listItemposition) 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-05
        • 2014-09-04
        • 1970-01-01
        • 2015-03-06
        • 1970-01-01
        相关资源
        最近更新 更多