我看到我的ListView出现了奇怪的行为,但我似乎无法解决它。
我有一个ListView,其中填充了一些数据。每一行包含一张图片和三个文本标签。这是我用于行的XML(我在适配器的
现在,文本字段中输入的任何内容都可以是任意长度(从几个字符到80-100个字符),我希望标签只是换行,并且行的高度会扩展以适应换行标签的高度。
我有一个ListView,其中填充了一些数据。每一行包含一张图片和三个文本标签。这是我用于行的XML(我在适配器的
getView
方法中进行膨胀):<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="0dip"
android:paddingBottom="0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/Icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:padding="2dp"
android:scaleType="fitCenter"
android:contentDescription="@string/app_icon"/>
<TextView android:id="@+id/TxtName"
android:scrollHorizontally="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@android:color/black"
android:background="@color/list_bg1"
android:layout_weight="2"
android:padding="2dp"/>
<TextView android:id="@+id/TxtPackage"
android:scrollHorizontally="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:textColor="@android:color/black"
android:background="@color/list_bg2"
android:padding="2dp"/>
<TextView android:id="@+id/TxtSource"
android:scrollHorizontally="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@color/list_bg3"
android:textColor="@android:color/black"
android:padding="2dp"/>
</LinearLayout>
现在,文本字段中输入的任何内容都可以是任意长度(从几个字符到80-100个字符),我希望标签只是换行,并且行的高度会扩展以适应换行标签的高度。
然而,标签确实可以正确换行,但是行的高度不会扩展,因此标签底部被截断。这是我的getView
方法:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SetInfo app = (SetInfo)getItem(position);
if(app == null)
return null;
LinearLayout row = (LinearLayout) (convertView == null
? LayoutInflater.from(context).inflate(R.layout.listitem, parent, false)
: convertView);
((TextView)row.findViewById(R.id.TxtName)).setText(app.getName());
((TextView)row.findViewById(R.id.TxtPackage)).setText(app.getPackage());
((TextView)row.findViewById(R.id.TxtSource)).setText(app.getSource());
if(app.getIcon() != null)
((ImageView)row.findViewById(R.id.Icon)).setImageDrawable(app.getIcon());
return row;
}
如何使行高自动调整以适应所有内容,并且可以设置不同的高度?