我使用以下代码生成循环进度。但是我不知道如何改变图案和颜色。

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="10%" android:pivotY="10%" android:fromDegrees="0"
    android:toDegrees="360">
    <shape android:shape="ring" android:innerRadiusRatio="0"
        android:thicknessRatio="6" android:useLevel="false">

        <size android:width="10dip" android:height="10dip" />
        <gradient android:type="linear" android:useLevel="false"
            android:startColor="#000000"
            android:endColor="#000000"
            android:angle="0"
             />
    </shape>
</rotate>


它产生了如下的循环进度:



但是我需要更改颜色和图案,如下所示:



我不想实现音乐图标。我只希望进度模式和颜色看起来像第二张图像。

最佳答案

您需要使用AnimationDrawable类来满足您的要求,

在res / drawable /文件夹中创建spin_animation.xml文件:

<!-- Animation frames are wheel0.png -- wheel5.png files inside the
 res/drawable/ folder -->
 <animation-list android:id="@+id/selected" android:oneshot="false">
    <item android:drawable="@drawable/wheel0" android:duration="50" />
    <item android:drawable="@drawable/wheel1" android:duration="50" />
    <item android:drawable="@drawable/wheel2" android:duration="50" />
    <item android:drawable="@drawable/wheel3" android:duration="50" />
    <item android:drawable="@drawable/wheel4" android:duration="50" />
    <item android:drawable="@drawable/wheel5" android:duration="50" />
 </animation-list>


使用以下代码执行,

 // Load the ImageView that will host the animation and
 // set its background to our AnimationDrawable XML resource.
 ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
 img.setBackgroundResource(R.drawable.spin_animation);

 // Get the background, which has been compiled to an AnimationDrawable object.
 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

 // Start the animation (looped playback by default).
 frameAnimation.start();

07-24 09:49
查看更多