且构网

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

如何调整一个ListView时添加新行?

更新时间:2023-09-11 11:19:52

但问题是你的的android:layout_height =WRAP_CONTENT

设置高度WRAP_CONTENT将仅显示前三行其余部分将被忽略。尽量做到为的android:layout_height =FILL_PARENT

Setting height as wrap_content will shows only first three rows rest will be ignored. Try to make it as android:layout_height="fill_parent"

由于罗曼盖伊(谷歌工程师workd的UI工具包),在他的帖子中称

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

通过设置宽度wrap_contentyou告诉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.

请记住:避免在任何时候都设置列表视图或GridView的WRAP_CONTENT,详细内容见本的谷歌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

动态地添加行到列表视图LINK_1

动态地添加行到列表视图LINK_2

Dynamically将行添加到列表视图Link_3

动态地添加行到列表视图Link_4