TableLayout,Text-Align to right

时间:2011-07-31 17:50:56

标签: java android tablelayout alignment

再一次:我。

我的“SingleItemAdvancedView”有一个TableLayout(http://imgur.com/XYdcg),我想怎么称呼它;) 问题是,我想要数据[TextViews没有字符串* Lbl作为android:文本集](所以 NOT 描述如:“name:”,“id:”等。 )显示在整个显示屏的右侧,而不是现在(它们显示在左侧表格列的旁边)。我尝试将布局与右侧对齐,以及仅将文本对齐(仅使用layout_gravity和gravity)。一切都行不通。我的宽度都设置为fill_parent,所以我根本不明白为什么。需要帮助!谢谢!

我的活动XML如下所示:

<?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="fill_parent">


  <TableRow>
    <TextView android:text="@string/idLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
               />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/itemidv" />
  </TableRow>
  <TableRow>
    <TextView android:text="@string/nameLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/namev" />
  </TableRow>
  <TableRow>
    <TextView android:text="@string/amountLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/amountv" />
  </TableRow>
  <TableRow>
    <TextView android:text="@string/unitLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/unitv" />
  </TableRow>
  <TableRow>
    <TextView android:text="@string/ppuLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/ppuv" />
  </TableRow>
  <TableRow>
    <TextView android:text="@string/totalLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/totalv" />
  </TableRow>
  <TableRow>
    <TextView android:text="@string/commentLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/commentv" />
  </TableRow>
   <TableRow>
    <TextView android:text="@string/enterqrLbl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    <TextView android:text=""
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:id="@+id/qrcodev" />
  </TableRow>
   <Button android:text="@string/delete"
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:id="@+id/deleteItemBtn"
           android:layout_marginTop="20dp"
           android:onClick="btnListener" />
</TableLayout>

1 个答案:

答案 0 :(得分:0)

您可以将android:stretchColumns =“0”添加到TableLayout。所以你会有这样的事情:

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

如果您希望两列均匀拉伸,则可以使用'*'而不是'0'。

相关问题