0

I am trying to design a ListView row layout with the following:

  1. A check box
  2. An image
  3. 3 text items. 2 at the top, 1 at the bottom. Where one of the top text items is right aligned.
  4. An image

It would look something like this:

Chk    Img    Left aligned small text        Right aligned small text    Img
Box    Btn1   Left aligned medium text                                   Btn2

No matter what I try, I cannot get the right aligned text to work properly. If I put the 2 top text items into a RelativeLayout and set the 2nd one to android:layout_alignParentRight="true" it gets aligned to the edge of the row, overlaying the 2nd image. The following is one of my many attempts:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<CheckBox
    android:id="@+id/cbSelect"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:layout_alignParentLeft="true"/>

<ImageView
    android:id="@+id/imgType"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:layout_toRightOf="@id/cbSelect"
    android:src="@android:drawable/btn_star_big_on"/>

<LinearLayout
    android:id="@+id/itmDetails"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:layout_toRightOf="@id/imgType"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:paddingLeft="8dp" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/txtTopLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:text="Top Left"/>

        <TextView
            android:id="@+id/txtTopRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:text="Top Right"/>

    </RelativeLayout>

    <TextView
        android:id="@+id/txtMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Main Item Text"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

</LinearLayout>

<ImageView
    android:id="@+id/imgStar"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:layout_alignParentRight="true"
    android:src="@android:drawable/btn_star"/>

</RelativeLayout>

Any suggestions?

Jim Rhodes
  • 5,021
  • 4
  • 25
  • 38
  • Try using `android:layout_width="fill_parent"` and `android:gravity="right"` in the desired `TextView` – Adil Soomro Oct 11 '13 at 04:49
  • @AdilSoomro I have tried that. The only thing that seems to get text to right justify is if it is in a RelativeLayout and I specifify `android:layout_alignParentRight="true"`. But when I do that, the text overlays the image on the right as though the parent is the outer RelativeLayout, not the one in which it is contained. – Jim Rhodes Oct 11 '13 at 13:04

0 Answers0