Skip to content Skip to sidebar Skip to footer

How To Have A Listview With Icons Beside The Text?

I'm trying to have a ListView with icon and text but there is a little problem as you can see in the screen shot (only a very small part of text is visible!): Here is the xml file

Solution 1:

Try setting layout_width of the ListView and TextView to fill_parent

EDIT: you're resetting list item width in the getView. Either remove or correct your code

Solution 2:

Use a relative layout for your rows and place the text right of the image as below :

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"><ImageViewandroid:id="@+id/lIcon"android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextViewandroid:id="@+id/lText"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@id/lIcon"/></RelativeLayout>

Solution 3:

Solution 4:

Try this layout for the row layout: Adjust the IDs to yours.. also notice the android:layout_toRightOf id.

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"
    ><ImageViewandroid:id="@+id/bimage"android:layout_height="20dip"android:layout_width="20dip"android:layout_gravity="left|center"android:layout_marginTop="10dip"android:layout_marginLeft="5dip"android:layout_alignParentLeft="true"android:layout_centerVertical="true"
         /><TextViewandroid:id="@+id/btitle"android:layout_toRightOf="@id/bimage"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_marginTop="8dip"android:paddingLeft="10dip"android:paddingRight="10dip"android:textSize="18dip"android:textColor="#ffffff"android:gravity="center_vertical"
        /></RelativeLayout>

Post a Comment for "How To Have A Listview With Icons Beside The Text?"