【问题标题】:In TableLayout TableRow align button right?在 TableLayout TableRow 中对齐按钮对吗?
【发布时间】:2012-03-08 08:19:16
【问题描述】:

我正在尝试将按钮对齐到 TableRow 的右侧。在 TableRow 里面我有两个文本视图和一个按钮。显示按钮时,中间的 textview 是隐藏的。这是通过将 textview 可见性设置为消失在我的适配器内部完成的。

我不确定在按钮显示时将其向右对齐的最佳方法是什么。

这是我的布局文件:

    <?xml version="1.0" encoding="UTF-8" ?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget28"
    android:stretchColumns="1"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:paddingLeft="10sp"
    android:descendantFocusability="blocksDescendants"
    >
    <TableRow>
    <TextView
     android:id="@+id/textTopLeft"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textAppearance="?android:attr/textAppearanceMedium">
    </TextView>
      <TextView
     android:id="@+id/textTopRight"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textAppearance="?android:attr/textAppearanceMedium">
    </TextView>
    </TableRow>
    <TableRow>
        <TextView
          android:id="@+id/textBottomLeft"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall">
        </TextView>
        <TextView
          android:id="@+id/textBottomRight"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall">
        </TextView>
        <Button
          android:id="@+id/btnSessionResume"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Resume"
          android:visibility="invisible"
          android:layout_marginRight="20px"
          android:layout_alignParentRight="true">
        </Button>
    </TableRow>
  </TableLayout>

按钮在底部的 TableRow 中。

这是当前布局的截图:

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    //使用 android:layout_span 并为你删除右边距按钮

    <?xml version="1.0" encoding="UTF-8" ?>
        <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/widget28"
        android:stretchColumns="1"
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:paddingLeft="10sp"
        android:descendantFocusability="blocksDescendants"
        >
        <TableRow android:layout_width="fill_parent"
              android:layout_height="wrap_content" android:layout_span="2">
        <TextView
         android:id="@+id/textTopLeft"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textAppearance="?android:attr/textAppearanceMedium">
        </TextView>
          <TextView
         android:id="@+id/textTopRight"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textAppearance="?android:attr/textAppearanceMedium">
        </TextView>
        </TableRow>
       <TableRow android:layout_width="fill_parent"
              android:layout_height="wrap_content">
            <TextView
              android:id="@+id/textBottomLeft"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceSmall">
            </TextView>
            <TextView
              android:id="@+id/textBottomRight"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceSmall">
            </TextView>
            <Button
              android:id="@+id/btnSessionResume"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Resume"
              android:visibility="invisible"
              android:layout_marginRight="5dp"
                  android:layout_alignParentRight="true">
            </Button>
        </TableRow>
      </TableLayout>
    

    【讨论】:

      【解决方案2】:

      也许您可以在表格行中有一个相对布局,然后在 TextViews 上使用 android:layout_alignParentLeft 并在按钮上使用 android:layout_alignParentRight。

      【讨论】:

      • 您好,感谢您的回答。我已经尝试过了,但它搞砸了第一行的文本视图。有什么想法吗?
      猜你喜欢
      • 2014-10-01
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 2011-04-21
      • 2011-09-16
      • 2012-08-24
      • 1970-01-01
      • 2019-11-04
      相关资源
      最近更新 更多