[英]Android - XML Custom shape
I'm trying to get this shape done in xml: 我正在尝试在xml中完成此形状:
What I have tried: 我试过的
<item>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/res_pressed"/>
<item
android:drawable="@color/res_default"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
android:left="15dp"/>
</layer-list>
</item>
Still I can't get it right with round and straight corners for the yellow shape. 对于黄色形状,我仍然无法正确地使用圆角和直角。
You need to use a shape
drawable so you can add a corners tag. 您需要使用可绘制的
shape
以便可以添加一个corners标签。 Try 尝试
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/res_pressed" />
<corners android:topLeft="10dp" android:bottomLeft="10dp" />
</shape>
</item>
<item
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
android:left="15dp">
<shape android:shape="rectangle">
<solid android:color="@color/res_default" />
<corners android:topRight="10dp" android:bottomRight="10dp" />
</shape>
</item>
</layer-list>
This is a workaround: 这是一种解决方法:
Create top.xml
创建
top.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark" />
<corners
android:radius="15dp"/>
</shape>
Create bot.xml
创建
bot.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
<corners android:radius="15dp" />
</shape>
The desired shape: 所需形状:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bot" />
<item
android:bottom="0dp"
android:drawable="@drawable/top"
android:left="15dp"
android:right="0dp"
android:top="0dp"/>
</layer-list>
Try this, identical to Gabe Sechan
post but with few modifications.. 尝试一下,与
Gabe Sechan
帖子相同,但修改很少。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="20dp"
>
<shape android:shape="rectangle">
<solid android:color="@color/yellow"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="10dp"
android:topRightRadius="0dp"
/>
</shape>
</item>
<item
android:bottom="0dp"
android:left="15dp"
android:right="0dp"
android:top="0dp">
<shape android:shape="rectangle">
<solid android:color="@color/blue"/>
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="0dp"
android:topRightRadius="10dp"/>
</shape>
</item>
</layer-list>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.