How to get gravity 'bottom' working on a drawable in xml

前端 未结 7 1470
南方客
南方客 2021-02-12 15:41

I have a simple aim. I want a light grey background on my FrameLayout with a black dividing line underneath it (only undernearth, not all around). So far I have this:

<         


        
相关标签:
7条回答
  • 2021-02-12 16:45

    I know it's pretty old question but given answers didn't work for me. Turns out in order to gravity property work you just need to add size tag in drawable item.

    So following will work as expected:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:gravity="center">
            <shape android:shape="rectangle">
                <solid android:color="#EEEEEE" />
            </shape>
        </item>
        <item
            android:gravity="bottom">
            <shape android:shape="line">
                <size android:height="2dp"/>
                <stroke android:width="1dip" android:color="#010101"/>
            </shape>
        </item>
    </layer-list>
    

    ps. this feature added in api level 23 https://developer.android.com/reference/android/graphics/drawable/LayerDrawable#setLayerGravity%28int,%20int%29

    0 讨论(0)
提交回复
热议问题