【问题标题】:How to align a TableLayout to the bottom of another TableLayout?如何将 TableLayout 与另一个 TableLayout 的底部对齐?
【发布时间】:2015-08-06 10:25:35
【问题描述】:

我正在尝试实现“电话拨号器”外观,但似乎无法使其正常工作。这是我的代码:

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="splitzerjoke.zickens.com.calcuhorario.nuevoHorario"
    style="?android:attr/buttonBarStyle" >

    <TextView
        android:textStyle="bold"
        android:textSize="32sp"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:id="@+id/nuevoHorario_lunes"
        android:text="@string/nuevoHorario_lunes"
        />

    <View
        android:layout_marginTop="10dp"
        android:layout_height="2dp"
        android:background="#999999"
        />
    <!-- Éstas son las filas para seleccionar las horas ocupadas -->

    <TableLayout
        android:layout_gravity="bottom"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:stretchColumns="0,1,2"
        >

    <TableRow>

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora1_lunes_texto"
            android:id="@+id/hora1_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora2_lunes_texto"
            android:id="@+id/hora2_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora3_lunes_texto"
            android:id="@+id/hora3_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

    </TableRow>

    <TableRow>
        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora4_lunes_texto"
            android:id="@+id/hora4_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora5_lunes_texto"
            android:id="@+id/hora5_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora6_lunes_texto"
            android:id="@+id/hora6_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />
    </TableRow>

    <TableRow>
        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora7_lunes_texto"
            android:id="@+id/hora7_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora8_lunes_texto"
            android:id="@+id/hora8_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora9_lunes_texto"
            android:id="@+id/hora9_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />
    </TableRow>

    <TableRow>
        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora10_lunes_texto"
            android:id="@+id/hora10_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora11_lunes_texto"
            android:id="@+id/hora11_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:text="@string/hora12_lunes_texto"
            android:id="@+id/hora12_lunes"
            android:layout_height="50dp"
            android:layout_width="wrap_content" />
    </TableRow>

        <TableRow>

            <Button
                style="?android:attr/buttonBarButtonStyle"
                android:layout_column="2"
                android:layout_height="50dp"
                android:layout_width="wrap_content"
                android:id="@+id/siguiente_lunes"
                android:text="@string/siguiente_lunes_texto"
                />

        </TableRow>

    </TableLayout>

</TableLayout>

预览看起来像这样: Preview

我想要做的是将所有这些蓝色按钮向下拖动,以便显示“¡Listo!”的按钮触底,其他的都跟着它;实现这一点真的很令人沮丧,任何帮助将不胜感激。

【问题讨论】:

  • 我在使用 TableLayout 时遇到了很多问题,例如绘图/重新创建视图等。请改用 RelativeLayout。它快速且相关。
  • 为什么要把根布局当成表格布局。为什么不使用相对或线性布局??
  • 使用RelativeLayout作为你的根布局,在你的TableLayout中做:android:alignParentBottom="true"
  • @zkminusck 谢谢!像魅力一样工作。
  • @zicken 我给出的答案比 ;)

标签: android xml button


【解决方案1】:

使用RelativeLayout 作为您的根布局,并在您的TableLayout 中执行:android:alignParentBottom="true"

【讨论】:

    猜你喜欢
    • 2012-08-21
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    相关资源
    最近更新 更多