我正在尝试创建一个用于我的android项目中的图像按钮的形状,它基本上有左半边和右边的半圆。
我想我可以使用半径为的形状XML。但是这只是围绕着我需要整个左右两侧的角落,如下图所示。
我当前形状的xml如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:color="@color/white">
<corners
android:radius="60dip"
/>
<stroke
android:width="0dp"
android:color="#000000" />
<solid
android:color="@color/white" />
</shape>
但我想尝试这个效果:
答案 0 :(得分:4)
您必须像这样指定每个角半径:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/green" />
<size android:height="30dp" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topRightRadius="15dp"
android:topLeftRadius="15dp"
/>
</shape>
您不应指定宽度,以便可以将宽度调整为背景可绘制。
答案 1 :(得分:1)
你的按钮有多高?可以使用带圆角的可绘制形状,您希望半径为按钮高度的一半。