Android更改Listview项目的高度

时间:2015-04-12 02:52:33

标签: android listview size

我在Android中有一个ListView对象,其中包含有toStrings写入4行文本的对象。

目前,ListView默认只显示每个元素的2行文本,而不是想要的4行。

我一直关注google和stackexchange,这样的大多数问题都是创建自定义XML并根据一些外部参数动态更改Listview中项目的高度。

在我解决制作自定义XML的麻烦之前,我只是想要改变listView,以便为listView中的每个元素显示4行而不是2行文本,这是一种愚蠢的简单方法吗?

3 个答案:

答案 0 :(得分:2)

最终发现此资源非常有用:

http://www.androidinterview.com/android-custom-listview-with-image-and-text-using-arrayadapter/

由于我使用simple_list_item_single_choice作为我的适配器的参数,我只是在Android' github上找到了它的源代码并将其复制到custom_list_view.xml中。

https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_list_item_single_choice.xml

并改变了

android:layout_height="?android:attr/listPreferredItemHeightSmall

android:layout_height="wrap_content"

然后我打电话给

adapter = new ArrayAdapter<String>(this, R.layout.custom_text_view, connections);

希望这可以帮助那些和我一样沮丧的未来谷歌用户。

答案 1 :(得分:0)

认为你制作了一个自定义的xml文件。不过,对于稍微大一点的观点来说,不应该做很多工作。

答案 2 :(得分:0)

YouTube有许多视频教程,例如Mybringback,The New Boston,并尝试本教程Custom Adapter