<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <solid android:color="@color/deep_gray" /> <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" /> <solid android:color="@color/backg_gray" /> <size android:width="30dp" android:height="30dp" /> </shape>
效果圖:android
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="10" android:useLevel="false" > <gradient android:centerColor="#FF6A6A" android:endColor="#FF0000" android:startColor="#FFFFFF" android:type="sweep" /> </shape> </rotate>
效果圖, 會轉圈圈:spa
注意:若是在控件中沒有設置寬和高,例如:控件設置了wrap_content,就須要在shape中設置寬和高:code
<size android:width="30dp" android:height="30dp" />
完整代碼:xml
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="10" android:useLevel="false" > <gradient android:centerColor="@color/backg_gray" android:endColor="@color/deep_gray" android:startColor="#FFFFFF" android:type="sweep" /> <size android:width="30dp" android:height="30dp" /> </shape> </rotate>