ListView Only add enough items to fill screen

时间:2016-04-15 15:00:36

标签: android listview

I have a listView that is populate via a RSS feed. The height of each item on the ListView can vary depending on the length on the content. Is there a way to only add enough items to the listView to fill the screen (the listView has a fixed height).

For example if each item only has one line of text I can fit 7, but if they have two lines of text I can only fit 5. I want to be able to programmatically decide when to stop adding items. I don't want the ListView to have to scroll.

EDIT

Let me rephrase. I don't want to just solve it but scrolling down. There may at some point in the development be content that gets added below the screen and requires scrolling but even in that case I don't want half an item showing at the bottom. Basically I don't want broken/half items showing at the bottom, if it's on the screen it should be the whole item that is showing. If not it should be below the bottom of screen.

1 个答案:

答案 0 :(得分:0)

尝试使用普通的线性布局,并在添加膨胀的行时,覆盖onMeasure以了解它是否适​​合屏幕。