Android 如何画一个完美的圆形按钮?
我想画一个完美的圆形按钮。 我尝试使用以下代码:Android 如何画一个完美的圆形按钮?,android,android-xml,android-button,Android,Android Xml,Android Button,我想画一个完美的圆形按钮。 我尝试使用以下代码: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <stroke android:width="3dip" android:color="#065a32" />
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke
android:width="3dip"
android:color="#065a32" />
<corners android:radius="10dip"/>
<solid android:color="#eaebec" />
</shape>
使用此xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid
android:color="#eaebec" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200"/>
<stroke android:width="2dp" android:color="#fff" />
</shape>
或者无论您需要的圆圈大小。使用此xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid
android:color="#eaebec" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200"/>
<stroke android:width="2dp" android:color="#fff" />
</shape>
在可绘制文件夹中创建以下内容 圆形按钮.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#ce2c2c" />
</shape>
输出<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#ce2c2c" />
</shape>
谢谢你的回答我尝试了你的代码,但仍然没有得到完美的循环。此外,我不能为我的视图提供常量参数,即它将根据屏幕大小而变化。如果它根据屏幕大小而变化,则根据屏幕大小在dimens.xml中定义大小。解决方案太麻烦,即无法替换android:layout\u width=“wrap\u content”android:layout\u height=“wrap\u content”我认为这不是一个完美的解决方案。你把它弄得太复杂了。如果我需要用不同的按钮SiZ.Maon做它,如果你想要它是圆的,你必须提供高度和宽度相等。如果你想用椭圆形xml定义高度和宽度,你可以在形状中书写。我的高度和宽度始终等于iam将按钮放在gridview中。你可以在photoshop中绘制圆形图像,并将其设置为按钮的背景。可以根据屏幕大小改变图像的分辨率。
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#ce2c2c" />
</shape>
android:background="@drawable/circular_button"