gpt4 book ai didi

Android ListView item getMeasuredHeight() 返回的值比真实值小

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

我整个上午都在为 Android 上的这个问题苦苦思索。我有一个 ListView,我需要为其计算高度。

我正在使用这段代码:

int totalHeight = 0;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
totalHeight += listItem.getMeasuredHeight();
}

然而,我在这里找到的 - 列表项的特定布局的返回值小于真实值(对于其他布局是准确的),最终使用它来重置列表的高度会删除的内容它。我看过很多关于这个的话题——其中一个提供了使布局中所有对象的高度为“wrap_content”的解决方案,例如,这对我不起作用。

我找不到任何适用于任何地方的东西。谁能帮忙?

真诚的,-李尔

最佳答案

经过大量搜索,我找到了这个线程:

How to force height of listView to be size so that every row is visible?

这给了我解决方案...有趣的是,我花了这么长时间才找到它,因为它比我之前在这个问题上浏览过的几十页要准确得多。

希望这有助于传播这个词:)

李尔

关于Android ListView item getMeasuredHeight() 返回的值比真实值小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19741521/

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