如何为API级别<23的项目设置重力

时间:2018-12-17 11:23:14

标签: android android-api-levels

如何为API级别<23的item内的layer-list设置重力?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:startColor="#A7A7A7"
                android:endColor="#C2C2C2"
                android:angle="315" />
            <corners
                android:topLeftRadius="14dp"
                android:topRightRadius="14dp" />
        </shape>
    </item>

    <item android:gravity="bottom"><!--This is not working-->
        <shape android:shape="rectangle">
            <solid android:color="#FF5F5D" />
            <size android:height="16dp" />
        </shape>
    </item>

</layer-list>

1 个答案:

答案 0 :(得分:1)

尝试这样

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FF5F5D" />
            <corners android:topLeftRadius="14dp"
                android:topRightRadius="14dp" />
        </shape>
    </item>

    <item
        android:bottom="16dp">
        <shape android:shape="rectangle"
            android:visible="true"
            android:dither="true"
            android:useLevel="false">
            <gradient
                android:startColor="#A7A7A7"
                android:endColor="#C2C2C2"
                android:angle="315" />
            <corners android:topLeftRadius="14dp"
                android:topRightRadius="14dp" />
        </shape>
    </item>
</layer-list>