gpt4 book ai didi

android - ListView 的 getChildCount 方法不返回可见项目数的准确计数

转载 作者:太空狗 更新时间:2023-10-29 14:21:34 25 4
gpt4 key购买 nike

我需要能够分辨 ListView 中的哪些项目是可见的。 onScroll 中的“visibleItemCount”项和listview.getChildCount这两个返回值通常比它们应该基于屏幕上实际可见的值高 1-3。这些项目不一定是相同的高度,这可能会导致失败。

更准确地读取可见内容的最佳方法是什么?

最佳答案

方法 getChildCount() 不应该返回可见 child 的数量,但是,正如文档所说:

Returns the number of children in the group.

要获取可见项的数量,您可能应该使用 getLastVisiblePosition()getFirstVisiblePosition() :

int visibleChildsCount=lv.getLastVisiblePosition()-lv.getFirstVisiblePosition();

关于android - ListView 的 getChildCount 方法不返回可见项目数的准确计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16447733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com