我在查找Android版XML中形状定义的文档时遇到了一些问题。我想在XML文件中定义一个用纯色填充的简单圆圈,以将其包含在布局文件中。
遗憾的是,android.com上的文档没有涵盖Shape类的XML属性。我想我应该用ArcShape来画一个圆,但没有关于如何设置大小、颜色或角度的说明。
我在查找Android版XML中形状定义的文档时遇到了一些问题。我想在XML文件中定义一个用纯色填充的简单圆圈,以将其包含在布局文件中。
遗憾的是,android.com上的文档没有涵盖Shape类的XML属性。我想我应该用ArcShape来画一个圆,但没有关于如何设置大小、颜色或角度的说明。
当前回答
如果你想要这样的圆圈
尝试使用以下代码:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false" >
<solid android:color="@android:color/white" />
<stroke
android:width="1dp"
android:color="@android:color/darker_gray" />
</shape>
其他回答
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/text_color_green"/>
<!-- Set the same value for both width and height to get a circular shape -->
<size android:width="250dp" android:height="250dp"/>
</shape>
</item>
</selector>
简单圆代码
<?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" />
<size android:width="80dp" android:height="80dp"/>
</shape>
尝试以下带破折号的代码:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="@dimen/_60sdp"
android:height="@dimen/_60sdp" />
<solid android:color="@color/black" />
<stroke
android:width="@dimen/_1sdp"
android:color="@color/white"
android:dashWidth="@dimen/_1sdp"
android:dashGap="@dimen/_1sdp" />
尝试不带破折号的代码:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="@dimen/_60sdp"
android:height="@dimen/_60sdp" />
<solid android:color="@color/black" />
<stroke
android:width="@dimen/_1sdp"
android:color="@color/white" />
你可以试试这个-
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="700"
android:thickness="100dp"
android:useLevel="false">
<solid android:color="#CCC" />
</shape>
此外,您可以通过调整android:厚度来调整圆的半径。
这是一个简单的圆圈,在Android中是可绘制的。
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="120dp"
android:height="120dp"/>
</shape>