2012-08-25 20 views
1

我使用下面的代码来生成循环进度。但我不知道如何改变它的图案和颜色。如何更改Android中circalar进度的颜色和模式?

<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> 

它产生像下面的圆形进度:

enter image description here

但我需要改变颜色和图案象下面这样:

enter image description here

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

回答

2

您需要使用AnimationDrawable类按您的需求,

创建资源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(); 
+0

其实,我不想搞砸Java。它不能只通过XML :( –

+2

规则是,当某些东西不是在API中,你需要创建自己的。我相信你提到的问题在API中没有,所以你必须去定制。 – Lucifer

1

你可以做的是创建一个具有所需形状和颜色的图像,然后旋转它。 Here是一个示例,显示如何完成。

+0

感谢@lalit Poptani的回复,我看到了你提到的例子。但它只是加载图像并旋转它。但我需要的是我需要得到充实的东西。就像从空白(只有背景,这里是深绿色)和一点一滴开始,它应该填充背景。如上所示。 –

+0

@praveenkumar:你是如何完成你的任务的?因为我正在寻找相同的解决方案。 – Sam

+0

@Sam使用上面接受的答案。 –