且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

一个ListView的Layout_width

更新时间:2022-12-08 14:21:44

通过设置宽度为WRAP_CONTENT你告诉ListView控件是一样宽最宽的孩子。因此,ListView控件必须衡量其项目,并得到它必须调用getView()上的适配器的项目。这种情况可能发生数次取决于布局的遍数,父布局的行为,等等。

By setting the width to "wrap_content" you are telling ListView to be as wide as the widest of its children. ListView must therefore measure its items and to get the items it has to call getView() on the Adapter. This may happen several times depending on the number of layout passes, the behavior of the parent layout, etc.

记住,不能保证按时间getView()上的适配器调用的数量,也没有在什么命令调用会发生。因此,您必须实现getView()要尽可能高效。底线是,这不是一个问题,它在这种情况下,预期的行为。

Remember there are no guarantees on the number of times getView() is invoked on the Adapter, nor in what orders the calls will happen. You must therefore implement getView() to be as efficient as possible. The bottom line is, this is not an issue, it's the expected behavior in this situation.