androidandroid-studioandroid-layoutandroid-bitmapandroid-gravity

How to add a margin top to a bitmap?


This is the drawable file :

<?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>

I want the bitmap to have 20px margin-top, I didn't find how to set margin-top to bitmaps element


Solution

  • You can try with android:top.

    The top offset in pixels.

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