如何设置不同的高度为在ListView各行? [英] How to set different heights for each row in a ListView?

查看:139
本文介绍了如何设置不同的高度为在ListView各行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题设置单行的高度在ListView。我已经看过上百个论坛和博客帖子,但似乎没有为我工作。

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.

我有一个 ArrayAdapter℃的ListView控件;排序> 。取决于Order对象的属性,不同布局中使用,具有不同的高度的每一行。然而,在结束时,所有的行具有相同的高度。我想这是给一个Ar​​rayAdapter的构造布局的高度。有谁知道如何控制每行单独的高度?

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

推荐答案

诀窍就是在你的布局的项目来看,你需要设置 layout_height WRAP_CONTENT ,仅此而已。

The trick is in the view in your layout item, you need to set the layout_height to wrap_content and that's it.

我做了截屏我的ListView的带型动物高的项目。

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 :

public static final String[] bzz = new String[] { "1", "2", "3", "4", "5" };
ArrayAdapter<String> addap = new ArrayAdapter<String>(this,
                R.layout.list_item, R.id.text_view, bzz);
lv.setAdapter(addap);

这篇关于如何设置不同的高度为在ListView各行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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