zoukankan      html  css  js  c++  java
  • 一个简单的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);
        }
    }
    
  • 相关阅读:
    51nod 1138 【数学-等差数列】
    hdoj3665【简单DFS】
    hdoj3664【DP】
    51nod1270 【dp】
    51nod 1069【思维】
    关于一些数学符号和概率的阐述;
    51nod 1428【贪心】
    51nod 1133【贪心】
    51nod1127【尺取】
    51nod1126【矩阵快速幂】
  • 原文地址:https://www.cnblogs.com/rainboy2010/p/6692499.html
Copyright © 2011-2022 走看看