如何调整一个ListView时添加新行? [英] How to resize a ListView when new rows are added?

查看:191
本文介绍了如何调整一个ListView时添加新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这样的:

...<!--Stuff above-->
<ListView 
     android:id="@+id/reminders_list"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"></ListView>
...<!--More stuff below-->

我的问题是,当我尝试添加更多不工作,因为适配器不添加更多的意见,如果没有更多的空间行。至少在这种情况下。这意味着我需要动态地调整其大小。问题是如何做到这一点?如果除了调整大小事情是可能的,我宁愿做。先谢谢了。

My problem is when I try to add more rows it does not work because the adapter doesn't add more views if there is no more space. At least in this instance. This means I need to resize it dynamically. Question is how to do this? If something besides resizing is possible I would rather do that. Thanks in advance.

推荐答案

但问题是你的的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

<一个href=\"http://stackoverflow.com/questions/3255650/styling-added-rows-to-arrayadapter-listview-android\">Dynamically将行添加到列表视图Link_3

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

这篇关于如何调整一个ListView时添加新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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