在Android列表视图中显示空行 [英] Displaying empty rows in Android listview

查看:133
本文介绍了在Android列表视图中显示空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想知道如何用空行填充 ListView ListView 是通过 SQLite db填充的,所以说例如列表中我只想填写3个项目屏幕的其余部分用空行。这是我的意思的屏幕截图。是的我知道它来自iPhone,但它证明了我的意思:

So I'm wondering how to go about filling a ListView with empty rows. The ListView is populated via SQLite db so say for instance there is only 3 items in the list I want to fill the rest of the screen with empty rows. Here is a screenshot of what I mean. Yes I know it's from iPhone but it demonstrates what I mean:

推荐答案

其他人已经躲过了,但我认为发布一个代码片段可能会有所帮助。如果有更好的技巧,如果我学到了什么,我会很乐意进行投票。

Others have eluded to it, but I thought it might help to post a code snippet. If there is a better technique, I will gladly take a down-vote if I learn something.

便宜的方法是在你的布局xml中添加额外的行。任何额外的行都将被屏幕截断。这可能会变得混乱:更高分辨率的屏幕可能需要您添加许多额外的TextView。由于它们被切断了,我想你可以根据自己的喜好添加多少。它看起来像这样:

The cheap way is to add extra "rows" in your layout xml. Any extra rows will be cut off by the screen. This can get messy: a higher-res screen might require you add many extra TextViews. Since they get cut off, I suppose you could add as many as you'd like. It would look something like this:

<LinearLayout>

<ListView></ListView>

<TextView/>
<TextView/>
<TextView/>
...

</LinearLayout>

如前所述,另一个选择是向ListView添加额外的行。如果绑定到数组,请向该数组添加额外的空行并适当地处理它。巧合的是,如果你使用光标,你可以使用MaxtrixCursor& MergeCursor,如本文所述: https://stackoverflow.com/a/16440093/103131

Another option is to add extra rows to your ListView, as mentioned previously. If you are bound to an array, add extra blank rows to the array and handle it appropriately. Coincidentally, if you are using a Cursor you can use a MaxtrixCursor & MergeCursor as described in this post: https://stackoverflow.com/a/16440093/103131

我最终使用了这些方法的组合。我尽力计算我想要添加到ListView中的行数,但是我在注意方面有错误,并且在我的ListView下面有一些TextViews使它们全部聚集在一起。

I ended up using a combination of these methods. I try my best to calculate the number of rows I want to add to my ListView, but I error on the side of caution and have a couple TextViews underneath my ListView that make it all come together.

这篇关于在Android列表视图中显示空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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