zoukankan      html  css  js  c++  java
  • android 图片进度条

    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方法即可

  • 相关阅读:
    Jdbc、Mybatis、Hibernate各自优缺点及区别
    java中的线程池原理
    JVN的理解
    "=="和 equals 方法究竟有什么区别?
    nginx基础之【study one】
    C#,WPF中使用多文本显示数据,并对其数据进行关键字高亮等操作
    C#、WPF中如何自定义鼠标样式
    SSM(Spring + Springmvc + Mybatis)框架面试题
    java基础面试题
    C#关于TreeView树在节点数较多时总是会出现闪烁的问题方法记录
  • 原文地址:https://www.cnblogs.com/beenupper/p/3735703.html
Copyright © 2011-2022 走看看