安卓:WRAP_CONTENT不工作与ListView控件 [英] Android: wrap_content is not working with ListView

查看:223
本文介绍了安卓:WRAP_CONTENT不工作与ListView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的机器人。我希望我的列表视图水平和不换行的内容来填充的宽度。该WRAP_CONTENT特性不工作。怎么办?

I am working on android. I want my list view to wrap its content horizontally and not to fill all the width. The wrap_content properties is not working. What to do?

推荐答案

随着罗曼盖伊表示在他的文章(谷歌工程师工作在UI工具包)

As Romain Guy (Google Engineer works on UI toolkit) Said in his post

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

By setting the width to wrap_contentyou 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.

所以,如果你设置布局宽度或你的ListView的布局高度 WRAP_CONTENT 在ListView将尝试测量一个连接到它的每一个单一的视图 - 这是绝对不你想要什么。

So if you set the layout width or layout height of your ListView to wrap_content the ListView will try to measure every single view that is attached to it - which is definitely not what you want.

请注意:避免设置 WRAP_CONTENT ,以便随时列表视图或GridView的,详细内容见本的Google I / O影片谈论的ListView的世界

Keep in mind: avoid setting wrap_content for ListViews or GridViews at all times, for more details see this Google I/O video talking about the world of listview

这篇关于安卓:WRAP_CONTENT不工作与ListView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆