【发布时间】:2018-03-11 18:21:48
【问题描述】:
我用xml创建加载动画并在activity中播放。
xml 文件:anim.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/loading_00001" android:duration="50" />
<item android:drawable="@drawable/loading_00002" android:duration="50" />
<item android:drawable="@drawable/loading_00003" android:duration="50" />
<item android:drawable="@drawable/loading_00004" android:duration="50" />
<item android:drawable="@drawable/loading_00005" android:duration="50" />
</animation-list>
activity中的方法:playAnimation
private void playAnimation() {
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setBackgroundResource(R.drawable.anim);
AnimationDrawable animation = (AnimationDrawable) imageView.getBackground();
animation.start();
}
得到:
需要创建相同的,但需要使用另一种方式 - 没有可绘制资源的自定义视图。仅以编程方式绘制。
类似这样的:
public CustomLoadingView extends View {
public CustomLoadingView(Context context) {
this(context, null);
}
public CustomLoadingView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
private void init(AttributeSet attrs) {}
@Override
protected void onDraw(Canvas canvas) {}
}
需要在CustomLoadingView里面写什么,才能得到这个
???
【问题讨论】:
标签: java android android-custom-view android-progressbar