1.创建一个类继承与Relativelaout并且实现它的两个方法
public class loding_progress_view extends RelativeLayout {
private ImageView outer;
public loding_progress_view(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public loding_progress_view(Context context){
super(context);
init();
}
2.创建一个init方法实现图片的提取和添加
private void init(){
//内部图片
ImageView inner=new ImageView(getContext());
inner.setImageResource(R.drawable.github_loading_inner);
addView(inner);
//外部图片
outer=new ImageView(getContext());
outer.setImageResource(R.drawable.github_loading_outer);
addView(outer);
}
3.引用一个onSizeChanged方法来实现外部的图片的旋转
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
RotateAnimation ra=new RotateAnimation(0,360,
getPivotX(),getPivotY());
ra.setDuration(1000);
ra.setRepeatMode(Animation.RESTART);
ra.setRepeatCount(Animation.INFINITE);
outer.startAnimation(ra);
}
4.在xml里面配置一个容器
<swu.lwk.a15_imageloading.loding_progress_view
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"/>
5.最终结果
1572698045316.gif