我有一个ListView,我希望它的高度是固定的(比如150dp)。然后,在ListView内部,对于单独的行,文本可能长度不同,所以我希望行的高度也是不同的。
目前为止,我只能让所有行具有相同的高度,因此长文本被截断了。
有没有办法解决这个问题?
目前为止,我只能让所有行具有相同的高度,因此长文本被截断了。
有没有办法解决这个问题?
终于成功了。
我使用以下适配器代码:
ArrayAdapter<String> mcqAnsAdapter = new
ArrayAdapter<String>(this, R.layout.mylist, mcqOptions);
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
/>
以上类似于Android定义的“simple_list_item_single_choice.xml”,只是我将高度更改为“wrap_content”。
奇怪的是,第一次尝试时它没有起作用。然后,我做了一些修改,再回到这个版本,它就可以工作了。不知道发生了什么。但无论如何,很高兴看到它能够工作。
感谢所有试图提供帮助的人们。非常感激。
现在,另一个问题——我能把复选标记放在文本左边而不是默认的右边吗?
convertedview.setlayoutparams(new listview.setlayoutparams(width, height));
试试这样做。它会起作用的。
您可以尝试将行的minHeight
设置为150dp,将height
设置为wrap_content
您应该使用自定义的list_item布局,这可能会有所帮助:Android Lists: ListActivity And ListView II – Custom Adapter And List Item View