【问题标题】:How to add a margin top to a bitmap?如何在位图上添加边距?
【发布时间】:2020-07-19 13:11:49
【问题描述】:

这是可绘制文件:

<?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 android-studio android-layout android-bitmap android-gravity


    【解决方案1】:

    你可以试试android:top

    以像素为单位的顶部偏移量。

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

    【讨论】: