图片实现动画

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,161评论 1 32
  • 原文地址:http://www.android100.org/html/201606/06/241682.html...
    AFinalStone阅读 1,027评论 0 1
  • 一. Java基础部分.................................................
    wy_sure阅读 3,854评论 0 11
  • 从小生活在蜜罐中,对于人心叵测无法用正常人的理解方式去面对。我是个倔强的人,一旦认定了某件事,某种东西,我一定会...
    逃避现实阅读 98评论 0 1
  • 口服给药后有些药物在进入全身循环之前首先在胃肠道内、肠黏膜细胞内和肝内被破坏掉一部分,导致进入全身循环的实际药量减...
    海蓝_09ad阅读 520评论 0 0