1、自定义loadingline动画

/** * 作者:created by meixi * 邮箱:13164716840@163.com * 日期:2018/9/6 10 */public class LoadingLine extends View {    private Paint paint;    private Paint backPaint;    private Paint textPaint;    private boolean init = false;    private ValueAnimator valueAnimator;    private float param = 0;    private int length = 0;    public LoadingLine(Context context) {        super(context);        init();    }    public LoadingLine(Context context, AttributeSet attrs) {        super(context, attrs);        init();    }    private void init() {        paint = new Paint();        paint.setColor(Color.BLUE);        paint.setStrokeWidth(25);        backPaint = new Paint();        backPaint.setColor(Color.RED);        backPaint.setStrokeWidth(25);        textPaint = new Paint();        textPaint.setColor(Color.WHITE);        textPaint.setTextSize(10);    }    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        if (!init) {//            start();            init = true;        }        int width = getWidth();        int height = getHeight();        canvas.drawLine(0, height / 2, width, height / 2, backPaint);        canvas.drawLine(0, height / 2, length * width / 100, height / 2, paint);        if (length<100){            canvas.drawText(length + "", length * width / 100 - 22, height / 2 + 6, textPaint);        }else {            canvas.drawText(length + "", length * width / 100 - 42, height / 2 + 6, textPaint);        }//        if (valueAnimator.isRunning()) {//            param = (float) valueAnimator.getAnimatedValue();//            setLength((int) param);//        }    }    /**     * 也可在外部手动控制进度条,自行关闭valueAnimator     *     * @param param     */    public void setLength(int param) {        this.length = param;        invalidate();    }    private void start() {        if (valueAnimator == null) {            valueAnimator = ValueAnimator.ofFloat(0, 100);            valueAnimator.setInterpolator(new LinearInterpolator());            valueAnimator.setDuration(6000);            valueAnimator.start();        } else {            valueAnimator.start();        }        postDelayed(new Runnable() {            @Override            public void run() {//                start();                invalidate();            }        }, valueAnimator.getDuration());        invalidate();    }}

 

2、activity调用

布局文件

初始化

    private boolean running;    private LoadingLine loadingLine;    int i = 0;    static final int REFRESH_COMPLETE = 0X1112;    private Handler mHandler = new Handler() {        public void handleMessage(android.os.Message msg) {            switch (msg.what) {                case REFRESH_COMPLETE:                    if (i==100){                        running=false;                    }                    Log.i("lgq","...===="+i);                    loadingLine.setLength(i++);//主要加载进度方法//todo...                    break;            }        }    };

线程加载进度

 loadingLine =(LoadingLine)findViewById(R.id.myloadline);new Thread() {    @Override    public void run() {        super.run();        running = true;        while (running) {            mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 0);            try {                sleep(100);            } catch (InterruptedException e) {                e.printStackTrace();            }        }    }}.start();

添加圆弧框

                    
<?xml version="1.0" encoding="utf-8"?>                

 

更多相关文章

  1. Android(安卓)API 中文(14) ―― ViewStub
  2. Android动态加载学习
  3. Android第三方异步网路加载库AsyncHttpClient内部实现缓存策略了
  4. 关于android应用程序的入口
  5. Android之使用Android-query框架进行开发(一)
  6. 2020-09-07
  7. Android插件化开发之DexClassLoader动态加载dex、jar小Demo
  8. [Android] 开发资料收集:动态加载、插件化、热修复技术
  9. Android中使用WebView, WebChromeClient和WebViewClient加载网页

随机推荐

  1. Process 'command 'C:\zssinstallsoft\
  2. android 主线程和子线程之间的消息传递
  3. Android学习中遇到的问题及解决方案
  4. Android Material Design : CollapsingTo
  5. android mtk6732 camera otp 加载流程
  6. Android应用程序键盘(Keyboard)消息处理机
  7. android ImageView 设置背景选择器select
  8. android 判断网络时打开设置
  9. Android TextView各种使用方法
  10. android AlarmManager