Aman Deep Gautam
Aman Deep Gautam

Reputation: 8777

Right and left align text views android

The following is the layout in one of my XML files.

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/name_available_device"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/address_available_device"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:gravity="start"
        android:layout_weight="1"
        android:ellipsize="end"
        android:textStyle="italic" />
    <TextView
        android:id="@+id/paired_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textStyle="italic"
        android:gravity="end" />
</LinearLayout>

The problem is that it is not working as expected which would be:

|First Row                     |
|second row              paired|

But this shows up when I run the application:

|First-Row                     |
|second-rowpaired              |

I am using this layout inside a listview with custom adapter. Can anyone tell me what's wrong here.

Upvotes: 0

Views: 56

Answers (2)

Cory Roy
Cory Roy

Reputation: 5619

You didn't set a weight for the second TextView either. Setting 0 makes it draw that one first before calculating the other ones.

<TextView
    android:id="@+id/address_available_device"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:gravity="start"
    android:layout_weight="1"
    android:ellipsize="end"
    android:textStyle="italic" />
<TextView
    android:id="@+id/paired_info"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textStyle="italic"
    android:layout_weight="0"
    android:gravity="end" />

Upvotes: 0

Aakash
Aakash

Reputation: 5261

do this to your linear layout

android:layout_width="match_parent"

Upvotes: 3

Related Questions