如何为位图添加边距顶部?

How to add a margin top to a bitmap?

这是可绘制文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
  <item>
    <color android:color="#ffffffff"/>
  </item>
  <item>
    <bitmap android:gravity="top|center_horizontal"
            android:src="@drawable/splash_screen"/>
  </item>
</layer-list>

我希望位图有 20px margin-top,我没有找到如何将 margin-top 设置为位图元素

你可以试试android:top

The top offset in pixels.

    <item
        android:top="20dp">
         <bitmap android:gravity="top|center_horizontal"
         android:src="@drawable/splash_screen"/>

    </item>