我用xml创建了加载动画,并在活动中播放。
xml文件:动画。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>
活动中的方法:播放动画
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中需要写什么才能得到这个