android创建自定义进度条

Pha*_*ong 0 android custom-controls android-progressbar

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

在此输入图像描述

我尝试使用

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingicon"
android:pivotX="50%"
android:pivotY="50%" />
Run Code Online (Sandbox Code Playgroud)

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

Iva*_*nyi 6

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

U必须绘制你未来进度条的所有状态(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>
Run Code Online (Sandbox Code Playgroud)

然后,在您的代码中:

 ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
 img.setBackgroundResource(R.drawable.pb_animation);
 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
 frameAnimation.start();
Run Code Online (Sandbox Code Playgroud)