Android開發之shape畫圓環的方法
阿新 • • 發佈:2019-02-02
方法一:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="8" android:useLevel="false"> <gradient android:centerColor="#ff0000" android:endColor="#0ff676" android:startColor="#B23AEE" android:useLevel="false" /> </shape>
效果圖如下:
方法二:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <stroke android:width="2dp" android:color="#ff0000" /> <size android:width="20dp" android:height="20dp" /> </shape>
效果如下:
方法三:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="100dp" android:shape="ring" android:thickness="10dp" android:useLevel="false"> <stroke android:width="10dp" android:color="#ff6652" /> <!--這裡可以看出shape中的android:thickness屬性和stoke中的android:width屬性的作用, android:thickness是圓環的寬度,而android:width是圓環邊緣線的寬度。如果設定成一樣, 就會如圖1所示,但這個一般不符合UI需求,會發現圓環寬度比較大,其實是android:thickness的2倍。 這裡其實不該用stoke,該用solid指定填充色就OK了。 而想要圖二效果的注意android:width一定要比android:thickness小。--> </shape>
效果如下: