可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have some problems finding the documentation of the definitions of shapes in XML for Android. I would like to define a simple circle filled with a solid color in an XML File to include it into my layout files.
Sadly the Documentation on android.com does not cover the XML attributes of the Shape classes. I think I should use an ArcShape to draw a circle but there is no explanation on how to set the size, the color, or the angle needed to make a circle out of an Arc.
回答1:
This is a simple circle as a drawable in Android.
回答2:
Set this as your view background

For solid circle use:

Solid with stroke:

Note: To make the oval
shapes appear as circle, in these examples, either your view that your are using these shapes as its background should be a square or you have to set the height
and width
properties of the shape tag to an equal value.
回答3:
回答4:
Look in the Android SDK samples. There are several examples in the ApiDemos project:
/ApiDemos/res/drawable/
- black_box.xml
- shape_5.xml
- etc
It will look something like this for a circle with a gradient fill:
回答5:
Use this

回答6:
Here's a simple circle_background.xml for pre-material:
You can use with the attribute 'android:background="@drawable/circle_background"
in your button's layout definition
回答7:
回答8:
回答9:
If you want a circle try using the code below:
回答10:
Just use
ShapeDrawable circle = new ShapeDrawable( new OvalShape() );