• 一个简单的Loading控件


    实现效果如下:

    使用方法:

    在layout文件中添加以下代码:

       <com.example.jack.ui.widget.RingLoading
            android:layout_width="20.0dip"
            android:layout_height="20.0dip"
       />

    具体代码如下:

    package com.example.jack.ui.widget;
    
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Matrix;
    import android.graphics.Paint;
    import android.graphics.SweepGradient;
    import android.util.AttributeSet;
    import android.view.View;
    
    /**
     * Created by pengf on 2017/4/10.
     */
    
    public class RingLoading extends View
    {
        private static final int PROGRESS = 5;
        private int centerX;
        private int centerY;
        private Context context;
        private int mProgressColor ;
        private Matrix matrix;
        private final Paint paint;
        private int roundWidth = 10;
        private int start = 0;
    
        public RingLoading(Context context, AttributeSet attrs)
        {
            super(context, attrs);
            this.context = context;
            this.paint = new Paint();
            this.paint.setAntiAlias(true);
            this.paint.setStyle(Paint.Style.STROKE);
            this.paint.setStrokeWidth(this.roundWidth);
            this.mProgressColor =Color.parseColor("#ffffcc00");
    
        }
    
        @Override
        protected void onDraw(Canvas canvas)
        {
            int center = getWidth() / 2;
            int radius = center - this.roundWidth / 2;
            SweepGradient sweepGradient = new SweepGradient(this.centerX, this.centerY, Color.TRANSPARENT, this.mProgressColor);
            this.paint.setShader(sweepGradient);
            this.matrix = new Matrix();
            this.matrix.postRotate(this.start, this.centerX, this.centerY);
            canvas.concat(this.matrix);
            canvas.drawCircle(center, center, radius, this.paint);
            this.start = (PROGRESS + this.start);
            invalidate();
        }
    
        @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh)
        {
            super.onSizeChanged(w, h, oldw, oldh);
            this.centerX = (w / 2);
            this.centerY = (h / 2);
        }
    }
    
  • 相关阅读:
    Java之正則表達式【使用语法】
    2015年创业中遇到的技术问题:71-80
    2015年创业中遇到的技术问题:71-80
    Kinect小小玩偶游戏----小小潜水员
    微信开发学习日记(三):6点经验
    微信开发学习日记(二):3个案例
    2015年创业中遇到的技术问题:61-70
    2015年创业中遇到的技术问题:61-70
    2次创业经验谈(想创业想做事的人不要错过)
    Kinect舒适区范围--UE4 的Blueprint测试范例
  • 原文地址:https://www.cnblogs.com/rainboy2010/p/6692499.html
Copyright © 2020-2023  润新知