簡體   English   中英

Android:無法將TableLayout的重力設置為Right

[英]Android: Cannot set gravity of TableLayout to Right

我知道關於此問題已經浮出水面,但我已經閱讀了很多問題,但仍然無法使我的第3列與右側對齊。

<?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>

我究竟做錯了什么?

無法使我的第3列向右對齊。

袖手旁觀,我懷疑嵌套的TableLayout小部件不能很好地工作。 盡管TableLayout旨在模仿HTML表“ API”,但類推還是有局限性的。

如果您希望“第三列右對齊”,請將所有內容放入外部TableLayout ,然后在該列中的所有小部件上嘗試android:layout_gravity="right"

我遇到了同樣的問題,並通過以下方法解決了該問題:

在TableRow屬性內,添加以下兩行:

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

如果您使用Layout_gravity = right,則由於某種原因它根本不起作用。 享受,阿德里安。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM