png图片

代码

ImageView loading=getActivity().findViewById(R.id.pro_loading);                LinearInterpolator lin = new LinearInterpolator();        am = new RotateAnimation ( 0, +360,        Animation.RELATIVE_TO_SELF, 0.5f,        Animation.RELATIVE_TO_SELF, 0.5f );         am. setDuration ( 1000 );//旋转一个周期的时长        am. setRepeatCount ( -1 );// 动画重复次数(-1 表示一直重复)        am.setRepeatCount(Animation.INFINITE);        am.setInterpolator(lin);         loading.setAnimation(am);        am.startNow();

因为有好多fragment要用到,所以封装了一下

终极类:

public class ProgressImageView extends ImageView {    private Animation am;    public ProgressImageView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);        init();    }        public ProgressImageView(Context context, AttributeSet attrs) {        super(context, attrs);        // TODO Auto-generated constructor stub        init();    }        public ProgressImageView(Context context) {        super(context);        // TODO Auto-generated constructor stub        init();    }        public void init(){        LinearInterpolator lin = new LinearInterpolator();        am = new RotateAnimation ( 0, +360,        Animation.RELATIVE_TO_SELF, 0.5f,        Animation.RELATIVE_TO_SELF, 0.5f );         am. setDuration ( 1000 );//旋转一个周期的时长        am. setRepeatCount ( -1 );// 动画重复次数(-1 表示一直重复)        am.setRepeatCount(Animation.INFINITE);        am.setInterpolator(lin);     }        /**     * 显示     */    public void show(){        setVisibility(View.VISIBLE);        this.setAnimation(am);        am.startNow();    }        /**     *隐藏      */    public void hide(){        this.clearAnimation();        setVisibility(View.INVISIBLE);    }}

        <com.lz.swc.view.ProgressImageView             android:id="@+id/pro_loading"            android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:src="@drawable/loading"            android:layout_centerInParent="true"            android:contentDescription="@string/tabspic"            android:visibility="invisible"            />

在xml中引用就可以了。调用 show hide方法即可

更多相关文章

  1. android 抽奖盘动画 自定义View
  2. Android开场透明度渐变动画
  3. ANDROID实现圆形图形不断旋转的动画
  4. Android学习笔记4——Activity的生命周期
  5. Android Activity淡入淡出动画
  6. android 动画的实现
  7. android 页面切换动画效果 转
  8. android: 生命周期
  9. Android View.startAnimation()动画

随机推荐

  1. 在剪贴板上读取/写入数据,太方便了吧!
  2. Python 为什么不支持 switch 语句?
  3. Python 疑难问题:[] 与 list() 哪个快?为什
  4. AWS上传证书-添加负载均衡
  5. 给你的Excel增加正则处理函数,简直如虎添
  6. 数据分析都有哪些岗位?
  7. 什么是好的数据指标:精益数据分析
  8. 为什么说 Python 内置函数并不是万能的?
  9. 如何处理偏态数据?
  10. SQL今日一题(6):count