【问题标题】:align a table in different layouts?以不同的布局对齐表格?
【发布时间】:2013-04-30 11:26:32
【问题描述】:

我在 LinearLayout 中并排使用 2 个表格,它们都填充了 50% 的屏幕宽度。在该 LinearLayout 下方,有一个 RelativeLayout,其中包含另一个表格。

类似这样的:

<LinearLayout>
      <TableLayout>
           <TableRow>
            ...
           </TableRow>
      </TableLayout>

      <TableLayout>
           <TableRow>
            ...
           </TableRow>
      </TableLayout>
</LinearLayout>

<RelativeLayout>

      ... some views ...

      <TableLayout>
           <TableRow>
            ...
           </TableRow>
      </TableLayout>
</RelativeLayout>

现在我希望RelativeLayout 中的表格与LinearLayout 中的第一个表格具有相同的宽度。我以为我可以用 android:layout_alignRight="@+id/Linearlayout_table1" 来做,但那行不通。

那么,有没有办法做到这一点?

【问题讨论】:

  • 要使该属性起作用,引用的布局应包含在 RelativeLayout 中。
  • 以及在RelativeLayout中绘制TableView后剩余的空间是什么......你要添加一些其他视图吗?

标签: android alignment android-linearlayout android-relativelayout


【解决方案1】:

您可以使用 LinearLayout 代替 RelativeLayout 并包含一个空元素以提供正确的权重。注意:将 layout_height 设置为您想要的任何值。

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TableLayout
            android:layout_width="0dp"
            android:layout_height="300dp"
            android:layout_weight="1" />

        <TableLayout
            android:layout_width="0dp"
            android:layout_height="300dp"
            android:layout_weight="1" />
    </LinearLayout>

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TableLayout
            android:layout_width="0dp"
            android:layout_height="300dp"
            android:layout_weight="1" />

        <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>

【讨论】:

    猜你喜欢
    • 2012-07-13
    • 2012-12-09
    • 2012-07-24
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多