0

似乎在尝试使用可用的 GUI 设计视图的位置(比如说命令按钮)时activity_main.xml,所有控件都相对于其他东西定位。

如果我查看实际的 xml 文件,我只能找到诸如将右边缘与父对象的右边缘对齐等属性。我需要做的是将控件定位在距屏幕边缘的某些偏移处,例如,让我们说,左边缘为 10% 屏幕宽度 + 距离屏幕左边缘 10 个像素,如果我在 Visual C++ 中设计 GUI,我将能够做到这一点。

有可能在Android中做到这一点吗?

4

1 回答 1

1

您可以为元素添加边距以将其从边缘移开。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" <!-- move it to the top left corner -->
        android:layout_alignParentLeft="true" <!-- move it to the top left corner -->
        android:layout_marginTop="10dp" <!-- move it 10dp down -->
        android:layout_marginLeft="10dp" <!-- move it 10dp right -->
        android:text="@string/hello_world" />

</RelativeLayout>
于 2013-09-13T03:17:52.560 回答