Reputation: 2446
I am trying to create a list view that will have an icon and a text in one row and a subtext in another row.
I created a custom adapter to support this and I do get an image, a text and a subtext, however each one is under the previous one. for example image IMDB account
my XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical" />
<TextView
android:id="@+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="20sp"
/>
<TextView
android:id="@+id/subString"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
I tried to move the image and the text to be under the first linear layout, but then everything is going crazy , and I can no longer see the text or the subtext any ideas?
thank you
Upvotes: 0
Views: 2573
Reputation: 86948
It might be easier to use one RelativeLayout, but this should give you the layout in your image:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="20sp" />
<TextView
android:id="@+id/subString"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Or do you want the layout that you described, not showed? Anyway with the layout that you posted you could only see the ImageView because the nested LinearLayout has vertical orientation and the ImageView's height was set to fill_parent
... So the TextViews were pushed off the bottom of the layout.
Upvotes: 1