Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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 1个居中按钮,如何在居中按钮上方放置另一个按钮10dp?安卓_Android_Xml_Android Relativelayout - Fatal编程技术网

Android 1个居中按钮,如何在居中按钮上方放置另一个按钮10dp?安卓

Android 1个居中按钮,如何在居中按钮上方放置另一个按钮10dp?安卓,android,xml,android-relativelayout,Android,Xml,Android Relativelayout,我有一个有两个按钮的视图。一个(按钮2)我把android:layout\u centerInParent=“true”放在屏幕的中心位置。现在我想把另一个(按钮1)放在按钮2上方,边距为10dp。我使用的是相对布局。我如何用xml写这个?我是否应该使用其他布局使其工作 My.xml代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.co

我有一个有两个按钮的视图。一个(按钮2)我把android:layout\u centerInParent=“true”放在屏幕的中心位置。现在我想把另一个(按钮1)放在按钮2上方,边距为10dp。我使用的是相对布局。我如何用xml写这个?我是否应该使用其他布局使其工作

My.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bakgrundsbild"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <Button
            android:id="@+id/button1"
            android:layout_width="280dp"
            android:layout_height="50dp"
            android:background="@drawable/nybutton"
            android:text="@string/las_sollefteabladet"
            android:layout_centerHorizontal="true"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="280dp"
        android:layout_height="50dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/nybutton"
        android:text="@string/annonsorer"
        android:layout_centerInParent="true"/>



</RelativeLayout>

像这样使用布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<Button
    android:id="@+id/button2"
    android:layout_width="280dp"
    android:layout_height="50dp"
    android:layout_centerInParent="true"
    android:layout_marginTop="10dp"
    android:text="annonsorer" />

<Button
    android:id="@+id/button1"
    android:layout_width="280dp"
    android:layout_height="50dp"
    android:layout_above="@+id/button2"
    android:text="las_sollefteabladet" /></RelativeLayout>

在上面添加图像..

android:layout_=“@+id/button2”


在Button1(居中位置)代码中使用此代码

它不起作用..Button1用此代码从屏幕上消失。当我在没有图像的情况下获取代码时,它起作用,但当我为按钮输入图像时,背景按钮1跳开。。奇怪的