【问题标题】:Toggle autoscroll of ListView - when scrolled interactively by user切换 ListView 的自动滚动 - 当用户交互滚动时
【发布时间】:2015-02-09 21:58:37
【问题描述】:

我有一个真正的应用程序 - 您可以在下面的屏幕截图左侧看到它。

而且我已经在GitHub准备了a very simple test app,你可以在右边看到:

真正的app底部有一个ListView,里面是蓝牙相关的日志信息。这种情况经常发生,每秒几次,并且用户不可能向上滚动并查看特定事件 - 因为当新事件添加到列表时,列表会自行跳到底部列表。

我的问题是:如何禁用ListView 的自动滚动 - 当用户向上滚动时以及如何在用户滚动到底部时再次启用自动滚动?

这是我非常简单的测试应用:

如您所见,布局中的 XML 属性当前启用了自动滚动:

<ListView 
    android:id="@+id/myListView"
    android:stackFromBottom="true"
    android:transcriptMode="alwaysScroll"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

【问题讨论】:

    标签: android android-listview autoscroll android-scroll


    【解决方案1】:

    好的,我已经为我的问题找到了完美的解决方案:

    <ListView 
        android:id="@+id/myListView"
        android:stackFromBottom="true"
        android:transcriptMode="normal"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    

    当transcriptMode设置为正常,那么:

    当有数据集时列表会自动滚动到底部 收到更改通知并且仅当最后一项已经存在时 在屏幕上可见。

    这里是my updated test project(我还添加了双击监听器以清除那里的ListView)

    【讨论】:

      猜你喜欢
      • 2016-03-11
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      相关资源
      最近更新 更多