android创建自定义progressbar,就像这样

android创建自定义progressbar,就像这样,android,custom-controls,android-progressbar,Android,Custom Controls,Android Progressbar,我想在android中创建一个progressbar,如图所示 我试着用 <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/loadingicon" android:pivotX="50%" android:pivotY="50%" /> 但我认为它不符合我的要求这里有一个定制progressbar的好例子: 你必须画出

我想在android中创建一个progressbar,如图所示

我试着用

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


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

这里有一个定制progressbar的好例子:

你必须画出你未来的所有状态进度条(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>

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

Android风格是开源的,所以你可以很容易地找到它们并根据你的需要进行扩展


祝你好运

最简单的解决方案可能是将gif动画解构为单独的帧,并创建一个(其中每个
都指向一个帧)。我尝试了这种近似方法,只需将样式应用到progressbar上,效果就非常好
 ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
 img.setBackgroundResource(R.drawable.pb_animation);
 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
 frameAnimation.start();