开发者

Android: Cannot set gravity of TableLayout to Right

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"
 开发者_JS百科 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?


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.


I had the same problem, and solved it with the following:

Inside the TableRow attributes add the two following lines:

android:layout_gravity="center"
android:gravity="right"

If you use the Layout_gravity = right, for some reason it does not work at all. Enjoy, Adrian.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜