I see a weird behavior with my ListView, which does not seem to get around.
I have a ListView that is populated with some data. Each line contains an image and three text labels. Here is my XML for the string (I inflate it in the Adapter getView
method):
<?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>
Now everything that is included in the text fields can be of any length (from several characters to 80-100 characters), and I want the labels to simply wrap and the height of the line to expand to fit the height of the wrapped label.
However, the labels wrap ok, but the line height does not expand, so the bottom of the labels is trimmed. Here is my getView
method:
@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; }
How can I have lines of different heights automatically adjusted to fit all content?
source share