Brian
Brian

Reputation: 7326

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.

Upvotes: 0

Views: 569

Answers (4)

user4272989
user4272989

Reputation:

Use layout_weight in text view .try this

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TableRow>
<TextView android:id="@+id/property_type_label"
    android:text="@string/property_type_label"
    android:layout_weight="1" />


<TextView android:id="@+id/property_type"
     android:text="@string/property_type"
    android:layout_weight="1" 
   />
 </TableRow>

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

 </TableLayout>

Upvotes: 1

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

Try to use weight to set right and left content :

<TableRow>
       <TextView
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:id="@+id/property_type_label"
           android:text="@string/property_type_label"/>
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/property_type"
           android:text="@string/property_type"/>
</TableRow>

Upvotes: 1

Ishtiaq
Ishtiaq

Reputation: 1206

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>

Upvotes: 1

Rami
Rami

Reputation: 7929

Add the height and width to TableRow and use the weight, something like that:

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

Upvotes: 1

Related Questions