¿Cómo cambiar el color y el patrón del progreso circular en Android?

I use the below code to generate the circular progress. But I don't know how to change the pattern and color of it.

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="10%" android:pivotY="10%" android:fromDegrees="0"
    <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"

It generated the circular progress like below:

enter image description here

But I need to change the color and pattern like below:

enter image description here

I don't want to implement the music icon. I just want the progress pattern and the color to look like the second image.

preguntado el 25 de agosto de 12 a las 06:08

2 Respuestas

Necesitas usar el AnimaciónDrawable class for your requirement,

create spin_animation.xml file in res/drawable/ folder:

<!-- 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" />

Use following code to execute,

 // 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);

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

 // Start the animation (looped playback by default).

Respondido 25 ago 12, 06:08

No actually, I don't want to mess up with Java. It can't be done only through XML :( - Praveen Kumar

Rule is, when something is not in API, you need to create your own. I am sure the images you mentioned in the question are not there in API, so you must go for customization. - Lucifer

What you can do is create an image with desired shape and color then rotate it. Here is an example that shows how that can be done.

Respondido 25 ago 12, 06:08

Thanks for the reply @lalit Poptani I saw the example which you had mentioned. But it just loads the image and rotates it. But what I need is I need something which gets filled. Like starting from empty(only background, here its dark green) and bit by bit, it should fill the background. like shown above. - Praveen Kumar

@praveenkumar: How did you accomplish your task? As I am looking for same solution. - Diana

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.