这是我的布局:
<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 的顶部。我觉得我缺少一个简单的基础知识,但我一直无法弄清楚。
最佳答案
这并不一定能解决RelativeLayout 的问题,但您始终可以将三个按钮组合在一个LinearLayout 中。这应该可以防止按钮重叠。
关于java - toRightOf 在 Android 布局中未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15797348/