[英]android create custom progressbar like that
我想像这样的图像在android中创建一个进度条
我尝试使用
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingicon"
android:pivotX="50%"
android:pivotY="50%" />
但我认为这不符合我的要求
这是自定义进度条的好例子: 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>
然后,用您的代码:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.pb_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();
您可以将AnimationDrawable与ImageView结合使用,并为加载指示器的每种状态添加一个drawable,但是一种更好的方法是为ProgressBar视图创建一个新的Style(通过扩展默认的平台样式)并使用AnimationDrawable作为加载指示器。
Android样式是开源的,因此您可以轻松找到它们并根据需要进行扩展。
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.