android创建自定义进度条

时间:2013-06-04 08:00:28

标签: android custom-controls android-progressbar

我想在Android中创建一个像该图像一样的进度条

enter image description here

我尝试使用

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingicon"
android:pivotX="50%"
android:pivotY="50%" />

但我认为它不符合我的要求

2 个答案:

答案 0 :(得分:6)

以下是自定义进度条的一个很好的示例:http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

你必须绘制未来进度条的所有状态(img1.png,img2.png,img3.png,img4.png)。将图片放到/res/drawable

pb_animation.xml:

<animation-list android:id="@+id/myprogressrbar" android:oneshot="false">
  <item android:drawable="@drawable/img1" android:duration="50" />
  <item android:drawable="@drawable/img2" android:duration="50" />
  <item android:drawable="@drawable/img3" android:duration="50" />
  <item android:drawable="@drawable/img4" android:duration="50" />
</animation-list>

然后,在你的代码中:

 ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
 img.setBackgroundResource(R.drawable.pb_animation);
 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
 frameAnimation.start();

答案 1 :(得分:1)

您可以将AnimationDrawable与ImageView结合使用,并为加载指示器的每个状态添加一个drawable,但更好的方法是为ProgressBar视图创建一个新样式(通过扩展de platform默认样式)和使用您的AnimationDrawable作为加载指示器。

Android风格是开源的,因此您可以轻松找到它们并根据您的需要进行扩展。

祝你好运!

相关问题