androidtextviewandroid-tablelayoutgravitylayout-gravity

Android TableRow TextView falls out of view on right side


I have a table which is intended to display a name followed by a value. The names should appear on the left of the row and the values on the right. Here is an example:

table example

This is my XML code:

<TableRow>
    <TextView android:id="@+id/property_type_label"
        android:text="@string/property_type_label"
        android:padding="3dip" />
    <TextView android:id="@+id/property_type"
        android:text="@string/property_type"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>

<View
    android:layout_height="2dip"
    android:background="#FF909090" />
</TableLayout>

The problem is that I cannot view the strings associated with the secondary TextView the TableRow. Ideally, a solution exists that does not involve a lot of manual padding. Also, android:layout_gravity="right" does not solve this problem.


Solution

  • Use the gravity for TextView instead of layout_gravity with weight to assign half of layout of each TextView

     <TableRow>
       <TextView android:id="@+id/property_type_label"
        android:text="@string/property_type_label"
        android:padding="3dip"
        android:layout_weight="1"
        android:gravity="left" />
    
        <TextView android:id="@+id/property_type"
        android:text="@string/property_type"
        android:layout_weight="1"
        android:gravity="right"/>
    </TableRow>