我一直在尝试在xml中重新创建一个背景图像(作为drawable).由于背景是一个简单的形状,如果它被创建为xml drawable会更好.
我试过的
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <size android:height="20dp" /> <gradient android:type="linear" android:startColor="@color/gradientLeft" android:centerColor="@color/gradientMiddle" android:endColor="@color/gradientRight" android:angle="0" /> </shape> </item> <item> <shape android:shape="oval"> <padding android:top="20dp" /> <gradient android:type="linear" android:startColor="@color/gradientLeft" android:centerColor="@color/gradientMiddle" android:endColor="@color/gradientRight" android:angle="0" /> </shape> </item> </layer-list>
我试图创建一个图层列表.该图层列表包含2个形状,矩形和椭圆形.
矩形具有渐变和20dp的高度(以进行测试).
椭圆形也具有相同的渐变,顶部填充为20dp.
但是,这不会创建圆形,而是使用渐变填充整个形状.有人能帮我吗?
解决方法
试试这个
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle" /> </item> <item android:bottom="300dp" android:left="-100dp" android:right="-100dp" android:top="-80dp"> <shape android:shape="oval"> <size android:height="20dp" /> <gradient android:angle="0" android:centerColor="@color/colorAccent" android:endColor="@color/red" android:startColor="@color/colorPrimary" android:type="linear" /> </shape> </item> </layer-list>
OUTPUT