Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在TableLayout TableRow中对齐按钮是否正确?_Android_Android Layout - Fatal编程技术网

Android 在TableLayout TableRow中对齐按钮是否正确?

Android 在TableLayout TableRow中对齐按钮是否正确?,android,android-layout,Android,Android Layout,我正在尝试将一个按钮与表格行的右侧对齐。在TableRow中,我有两个文本视图和一个按钮。显示按钮时,中间的文本视图将隐藏。这是在我的适配器内通过将textview可见性设置为gone来完成的 我不确定当按钮显示时,将其向右对齐的最佳方法是什么 这是我的布局文件: <?xml version="1.0" encoding="UTF-8" ?> <TableLayout xmlns:android="http://schemas.android.com/apk/r

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

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

这是我的布局文件:

    <?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>
按钮在最下面的一行

以下是当前布局的屏幕截图:


//使用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>

也许您可以在表格行中使用相对布局,然后在文本视图上使用android:layout\u alignParentLeft,在按钮上使用android:layout\u alignParentRight。

您好,谢谢您的回答。我已经试过了,但是它把最上面一行的文本视图搞砸了。有什么想法吗?