java - toRightOf 在 Android 布局中未按预期工作

标签 java android xml

这是我的布局:

<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 代码中使用文本或检查填充它们。它们可以为空。然后我有三个按钮。前两个按钮在屏幕上显示得很好。第三个按钮位于第一个按钮的顶部: enter image description here

我将第三个按钮(backButton)更改为 toRightOf SubmitButton 只是为了看看会发生什么。正如预期的那样,它位于 cancelButton 的顶部。我觉得我缺少一个简单的基础知识,但我一直无法弄清楚。

最佳答案

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

关于java - toRightOf 在 Android 布局中未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15797348/

相关文章:

java - 使用 Groovy 动态更改 Java 应用程序的行为

java - 插入/使用 CompletionProposal 的 eclipse 插件扩展点

android - Google Android 会支持 .NET 吗?

java - 使用 lib 添加自定义字体 android

java - 修改集合会使实体变脏

java - 闰年程序问题——似乎无法让它正常运行

android - 如何动态设置偏好值?

android - 如何在android中设置定时器?

c++ - 使用 msxml2 IXMLDOMDocument2 删除 XML 声明

c# - 以编程方式从 XML 模式生成测试 XML