Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 相对布局中的按钮定位问题_Android_Button - Fatal编程技术网

Android 相对布局中的按钮定位问题

Android 相对布局中的按钮定位问题,android,button,Android,Button,我在一个项目中遇到了结构问题。在每个模拟器(也是大屏幕)上,一个按钮使用该代码定位在一个简单的相对布局中 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout1" android:layout_width="fill_

我在一个项目中遇到了结构问题。在每个模拟器(也是大屏幕)上,一个按钮使用该代码定位在一个简单的相对布局中

    <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/first_bg" >

    <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="202dp"
        android:layout_marginRight="54dp"
        android:background="@drawable/m_button"
        android:text="@string/next" />

</RelativeLayout>


看起来不错。但在Galaxy Note上测试该应用程序表明,该按钮会飞到一些疯狂的位置。我使用了一个具有类似配置的仿真器,按钮显示正确。我不知道问题出在哪里

您是否尝试过使用线性布局?
使用它,您无需设置边距,只需设置位置,它基于与密度无关的像素(dp单位),它将显示在不同手机的不同位置


我猜您可以在adt插件的GUI编辑器上安排按钮的位置,它会为您提供这些边距。相反,可以尝试直接在xml中编写GUI或使用GUI,但要注意编辑器是否自行添加了边距。我尝试了两种方法,也尝试了手动定义边距的线性布局。。但在Galaxy Note上启动应用程序时,那个该死的按钮就是不想停留在正确的位置。o_0清理你的项目并从手机上卸载它。然后再试一次,有时xml资源会乱七八糟。但是,我猜您的xml有问题。您可以发布一个屏幕截图,说明您尝试的最后一个xml应该是什么样子,以及它现在是如何显示的。