如何为ListView中的每一行设置不同的高度?
我在设置 ListView 中单行的高度时遇到问题。我已经阅读了数百个论坛和博客文章,但似乎没有什么对我有用。
我有一个带有 ArrayAdapter
的 ListView。根据 Order 对象的属性,使用不同的布局,每行具有不同的高度。然而,最终所有行都具有相同的高度。我想它是赋予 ArrayAdapter 构造函数的布局高度。有谁知道如何单独控制每一行的高度?
感谢您的回答, 菲利普
I have problem setting the height of a single row in a ListView. I have already read hundreds of forums and blog posts, but nothing seems to work for me.
I have a ListView with an ArrayAdapter<Order>
. Depending on an attributes of the Order object, different Layouts are used, with different heights for each row. However, in the end, all rows have the same height. I suppose it is the height of the layout given to the constructor of the ArrayAdapter. Does anybody know how to control the height of each row separately?
Thanks for your answers,
Filip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
诀窍在于布局项中的视图,您需要将
layout_height
设置为wrap_content
就这样了。我用不同高度的项目制作了 listView 的屏幕截图。
如果您是初学者,这将为您提供一个起点:
The trick is in the view in your layout item, you need to set the
layout_height
towrap_content
and that's it.I made the screen shot of my listView with items with differents heights.
in case you are beginner, this will give you a starting point :
我通过更改代码来解决此问题,如下所示
list_item
布局属性中添加android:layout_height="wrap_content"
android:inputType=
list_item
文本视图中的“textMultiLine”希望它也适合您。
I solve this problem by changing my code as follow
android:layout_height="wrap_content"
inlist_item
layout propertiesandroid:inputType="textMultiLine"
in text view inlist_item
hope it works for you too.