tags:

views:

53

answers:

1

I know there are tons of questions about this already floating around SO but I've read a bunch of them and still cannot get my 3rd column to align to the right.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:background="#FFFFFF"
  android:stretchColumns="2"
 >
  <TableRow>

 <ImageView 
  android:src="@drawable/blue_light" 
  android:layout_height="48px" 
  android:layout_width="48px" 
  android:padding="3dp"
  android:layout_margin="3dp"
  android:layout_column="1"/>   

   <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_marginLeft="10px"
   android:layout_gravity="center_vertical"
   android:layout_column="2">

   <TableRow>
    <TextView 
     android:id="@+id/row_title"  
     android:textColor="#000000" 
     android:layout_width="wrap_content" 
      android:layout_height="wrap_content"  
      android:textStyle="bold" />
   </TableRow>

   <TableRow>
    <TextView 
     android:id="@+id/row_author"  
     android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
      android:textColor="#9E9E9E"  
      android:textStyle="italic|bold"/>
   </TableRow>

   </TableLayout>

   <TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_column="3"
    android:layout_gravity="center_vertical|right"
  android:gravity="center_vertical|right"
   >

   <TableRow>
    <TextView 
     android:textColor="#1F9C29" 
     android:textSize="15dp" 
     android:id="@+id/row_txt1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold" />
   </TableRow>

   <View
    android:layout_height="1dp"
    android:background="#000000"
    android:layout_marginRight="3dp"
    />

   <TableRow>
    <TextView 
     android:textColor="#1B27D1" 
     android:id="@+id/row_txt2"
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold"/>
   </TableRow>

   </TableLayout>
  </TableRow>
</TableLayout>

What am I doing wrong?

+1  A: 

cannot get my 3rd column to align to the right.

Off the cuff, I suspect that nested TableLayout widgets will not work terribly well. While TableLayout was designed to mimic the HTML table "API", there are limits to the analogy.

If you want the "3rd column to align to the right", put everything into the outer TableLayout, then try android:layout_gravity="right" on all widgets in that column.

CommonsWare
Yup that was it. I moved to using nested LinearLayouts within the TableLayout to simplify the XML. Thanks!
Adam Driscoll