在ExpandableListView中自动滚动

在ExpandableListView中自动滚动

本文介绍了在ExpandableListView中自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的ExpandableListView在用户展开组时自动滚动,以使展开的组标题位于屏幕顶部.我已经尝试过smoothScrollToPosition,但这只是确保扩展的组在屏幕上的某个位置可见.我想显式滚动它,以使展开的组位于顶部,如以下示例所示:

I would like my ExpandableListView to automatically scroll when the user expands a group, so that the expanded group header is at the top of the screen. I've tried smoothScrollToPosition, but this merely ensures the expanded group is visible somewhere on the screen. I would like to explicitly scroll it so the expanded group is at the top, like in this example:

Before expanding Group 3:                After expanding Group 3:

+=================+                      +=================+
| Group 1         |                      | Group 3         |
+-----------------+                      +-----------------+
| Group 2         |                      |   Grp 3 Child 1 |
+-----------------+                      +-----------------+
| Group 3         |                      |   Grp 3 Child 2 |
+-----------------+                      +-----------------+
| Group 4         |                      | Group 4         |
+=================+                      +=================+

推荐答案

ListView.setSelection(position)

这将滚动到所选项目,当您单击组项目时调用此名称.

this will scroll to the selected item,call this when u click on the group item.

这篇关于在ExpandableListView中自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:56