Android gravity is not working in drawable on older versions

416 Views Asked by At

I have a drawable which I am using in some scrolling fragment views. This is an image which should be sticky at the bottom of the page, should not scroll with the scroll view and should not stretch.

The drawable:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/ic_emptystate_buildings"
        android:gravity="bottom|center_horizontal" />
</layer-list>

Setting this drawable as background like this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_buildings_grey"
    android:orientation="vertical">

works exactly as I want on newer devices, but when I tried on a Samsung S4 with Android 5.0.1, the drawable background streches all the way to the top. The image ('ic_emptystate_buildings' - an imported vector drawable) is only maybe 100dp tall and should not be stretched and should stick to the bottom.

The reason I did not create an ImageView was because its the background of a ScrollView and the XML got messy when I tried to 'hack' it to work. I also want this behaviour in multiple views, so this solution seemed the best because of no duplicate code and simple, clean XML.

Does anyone know why its not working on older versions, and perfectly on newer? And more importantly; is there any nice way to fix this?

0

There are 0 best solutions below