Search code examples
androidandroid-drawablexml-drawable

XML Drawable place image 1/4 from top


I am trying to create a "splash screen" preview theme as per:

i.e. a theme that places an XML drawable as the background, which then gets displayed while Android loads up the first activity layout.

I have been using these techniques on basic layouts for years, all the time assuming that there was no solution for more complex layouts, like this question. Today I decided to question the assumption.


It is easy to overlay one image on top of another, and to centre the smaller image using a LayerDrawable:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap
            android:src="@drawable/background" />
    </item>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/logo" />
    </item>
</layer-list>

What I want to do is place the logo exactly 1/4 of the screen height down from the top.

Is there a solution to this yet, that can be used in an XML drawable file?


Update based on comment by DavidH - Can a custom LayerDrawable subclass be added to a drawable XML file, which is then used as part of an application theme?


Solution

  • It is not possible. Relative measurements inside XML layouts are not supported.