表格布局,文本右对齐

发布于 2024-11-27 08:17:21 字数 3857 浏览 5 评论 0原文

再说一遍:我。

我有一个 TableLayout (http://imgur.com/XYdcg)用于我的“SingleItemAdvancedView”,我喜欢这样称呼它;) 问题是,我想要数据[没有字符串 *Lbl 作为 android:text 设置的 TextView](所以像这样的描述:“name:”,“id:”等。 )显示在整个显示屏的右侧,不像现在(它们显示在左表列旁边)。我尝试将布局与右侧对齐,并且仅将文本对齐(仅使用布局重力和重力)。一切都不起作用。我的宽度都设置为 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>

once more: me.

I have a TableLayout (http://imgur.com/XYdcg) for my "SingleItemAdvancedView" how i like to call it ;)
The thing is, I want the data [the TextViews which don't have string *Lbl as android:text set] (so NOT the description like : "name:" , "id:" etc.) to be displayed on the right side of the whole display, not like it's now ( they are displayed right next to the left table-column). I tried to align the layout to the right side, as well as only the text (with layout_gravity and gravity only). everything didn't work. My widths are all set to fill_parent , so I simply don't understand why. Help needed! Thanks!

My XML for the activity looks like this:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-12-04 08:17:21

您可以将 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”。

You could add android:stretchColumns="0" to TableLayout. So you would have something like this:

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

If you want both columns to stretch equally you could use '*' instead of '0'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文