限制ExpandableListView内的子级列表的可见项数量,并允许它们滚动

时间:2019-05-16 15:25:39

标签: android android-layout android-listview android-expandable-list-view

是否有一种方法可以在扩展组时仅显示子项的子集,并允许用户滚动子项列表以访问Android ExpandableListView中的其余元素?

var shouldLimitChildrenCount:Boolean = true

override fun getChildrenCount(groupPosition: Int): Int {
    if (shouldLimitChildrenCount) {
        return 5 // show only 5 elements
    }
    return children.size // actual size
}

override fun onGroupExpanded(groupPosition: Int) {
    shouldLimitChildrenCount = false
}

override fun onGroupCollapsed(groupPosition: Int) {
    shouldLimitChildrenCount = true
}

尝试了上述方法,但是子级列表不会滚动,并且始终显示前5个子级项!

0 个答案:

没有答案