2

这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/outerBox"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" >

<GridLayout
    android:id="@+id/checksHere"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:columnCount="5"
    android:columnWidth="100dp" />

<GridLayout
    android:id="@+id/textHere"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/checksHere"
    android:columnCount="4" />

<Button
    android:id="@+id/submitButton"
    android:layout_width="185dip"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/outerBox"
    android:layout_below="@id/textHere"
    android:layout_margin="3dip"
    android:onClick="submit"
    android:text="@string/submit" />

<Button
    android:id="@+id/cancelButton"
    android:layout_width="185dip"
    android:layout_height="wrap_content"
    android:layout_below="@id/textHere"
    android:layout_margin="3dip"
    android:layout_toRightOf="@id/submitButton"
    android:onClick="next"
    android:text="@string/cancel" />

<Button
    android:id="@+id/backButton"
    android:layout_width="185dip"
    android:layout_height="wrap_content"
    android:layout_below="@id/textHere"
    android:layout_margin="3dip"
    android:layout_toRightOf="@id/cancelButton"
    android:onClick="next"
    android:text="test" />

</RelativeLayout>

我有一个相对的布局。该布局在顶部有两个网格布局,可以在我的 java 代码中填充文本或检查。它们可以是空白的。然后我有三个按钮。前两个按钮在屏幕上显示得很好。第三个按钮位于第一个按钮的顶部: 在此处输入图像描述

我将第三个按钮 (backButton) 更改为 toRightOf submitButton 只是为了看看会发生什么。正如预期的那样,它位于 cancelButton 之上。我觉得我错过了一个简单的基本原理,但我一直无法弄清楚。

4

2 回答 2

4

好吧,这不一定能解决RelativeLayout 的问题,但您总是可以将三个按钮组合在一个LinearLayout 中。这应该可以防止按钮重叠。

于 2013-04-04T20:00:35.003 回答
0

我不确定,但是在 Eclipse 中进行测试时,将所有按钮更改android:layout_width="185dip"android:layout_width="wrap_content"对我有用。

于 2013-04-03T21:40:29.490 回答