Android 我能';t在我的飞溅屏幕的顶部中央没有红色的矩形

Android 我能';t在我的飞溅屏幕的顶部中央没有红色的矩形,android,android-layout,Android,Android Layout,我是android开发的新手。 我试图创建我的第一个Splashscreen,顶部中间有一个红色矩形,背景为紫色,如第一张图片所示: 但由于我的代码,我得到了这样的结果: 这是我的代码: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="0dp" androi

我是android开发的新手。 我试图创建我的第一个Splashscreen,顶部中间有一个红色矩形,背景为紫色,如第一张图片所示:

但由于我的代码,我得到了这样的结果:

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="0dp" android:paddingEnd="0dp" android:paddingStart="0dp">

Background_splash.xml:
   <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="0dp" android:paddingEnd="0dp" android:paddingStart="0dp">

    <item>
        <bitmap
            android:gravity="fill_horizontal|fill_vertical"
            android:src="@drawable/purple_rectangle"
            />
    </item>
    <item>
        <bitmap android:src="@drawable/red_rectangle"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp" />
    </item>
</layer-list>

Background_splash.xml:
所以你能帮我纠正我的代码,在顶部加上红色的矩形,然后像第一幅图一样缩小。 谢谢你的帮助



这对于线性布局很容易

将您的形状置于相对位置。然后为您的应用程序添加此属性

 android:layout_centerHorizontal="true"
 android:android:layout_alignParentTop="true"

谢谢kelvin,但我不能在android studio中的xml文件中使用LinearLayout,这给了我一个错误,我应该定义它复制粘贴到您的活动的xml文件中
 android:layout_centerHorizontal="true"
 android:android:layout_alignParentTop="true"