|
|
@@ -3,16 +3,21 @@ package com.tongyu.luck.happywork.baselibrary.widget;
|
|
|
import android.animation.ArgbEvaluator;
|
|
|
import android.content.Context;
|
|
|
import android.graphics.Canvas;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.graphics.LinearGradient;
|
|
|
import android.graphics.Paint;
|
|
|
import android.graphics.RectF;
|
|
|
+import android.graphics.Shader;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
+import com.tongyu.luck.happywork.baselibrary.utils.PxUtils;
|
|
|
+
|
|
|
public class IntegralTaskPercentView extends LinearLayout {
|
|
|
private int mWidth;//控件宽度
|
|
|
private int mHeight;//控件高度
|
|
|
+ private float percent;//百分比
|
|
|
private Context mContext;
|
|
|
- private ArgbEvaluator argbEvaluator = new ArgbEvaluator();
|
|
|
|
|
|
public IntegralTaskPercentView(Context context, AttributeSet attrs) {
|
|
|
super(context, attrs);
|
|
|
@@ -43,15 +48,28 @@ public class IntegralTaskPercentView extends LinearLayout {
|
|
|
@Override
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
super.onDraw(canvas);
|
|
|
-// int width = (int) ((mWidth - mPadding * 2) / mCountNum);
|
|
|
-// float offsetWidth = mPercent * width;
|
|
|
-// Paint p = new Paint();
|
|
|
-// p.setStyle(Paint.Style.FILL);//充满
|
|
|
-// p.setColor(mSelectColor);
|
|
|
-// p.setAntiAlias(true);// 设置画笔的锯齿效果
|
|
|
-// RectF oval3 = new RectF(mPadding + mPosition * width + offsetWidth + mWidthPaddingPercent * width, mHeight - mIndicatorHeight - mPadding, mPadding + mPosition * width + offsetWidth + mWidthPaddingPercent * width + mWidthPercent * width, mHeight - mPadding);// 设置个新的长方形
|
|
|
-// canvas.drawRoundRect(oval3, mIndicatorHeight / 2, mIndicatorHeight / 2, p);//第二个参数是x半径,第三个参数是y半径
|
|
|
-
|
|
|
+ canvas.drawColor(Color.WHITE); //白色背景
|
|
|
+ Paint paint = new Paint();
|
|
|
+ paint.setStyle(Paint.Style.FILL);//充满
|
|
|
+ paint.setAntiAlias(true); //设置画笔为无锯齿
|
|
|
+ paint.setColor(Color.parseColor("#EEEEEE")); //设置画笔颜色
|
|
|
+ RectF r1 = new RectF(); //RectF对象
|
|
|
+ r1.left = 0; //左边
|
|
|
+ r1.top = 0; //上边
|
|
|
+ r1.right = mWidth; //右边
|
|
|
+ r1.bottom = mHeight; //下边
|
|
|
+ canvas.drawRoundRect(r1, PxUtils.dip2px(3), PxUtils.dip2px(3), paint); //绘制圆角矩形
|
|
|
+ Paint paint2 = new Paint();
|
|
|
+ paint2.setStyle(Paint.Style.FILL);//充满
|
|
|
+ paint2.setAntiAlias(true); //设置画笔为无锯齿
|
|
|
+ Shader shader = new LinearGradient(0, mHeight / 2, mWidth * percent, mHeight / 2, Color.parseColor("#40AEFF"), Color.parseColor("#408FFF"), Shader.TileMode.CLAMP);
|
|
|
+ paint2.setShader(shader);
|
|
|
+ RectF r2 = new RectF(); //RectF对象
|
|
|
+ r2.left = 0; //左边
|
|
|
+ r2.top = 0; //上边
|
|
|
+ r2.right = mWidth * percent; //右边
|
|
|
+ r2.bottom = mHeight; //下边
|
|
|
+ canvas.drawRoundRect(r2, PxUtils.dip2px(3),PxUtils.dip2px(3) , paint2); //绘制圆角矩形
|
|
|
}
|
|
|
|
|
|
private int measureSize(int measureSpec) {
|
|
|
@@ -70,15 +88,11 @@ public class IntegralTaskPercentView extends LinearLayout {
|
|
|
/**
|
|
|
* 移动指示点
|
|
|
*
|
|
|
- * @param percent 比例
|
|
|
- * @param position 第几个
|
|
|
+ * @param percent 比例
|
|
|
*/
|
|
|
- public void move(float percent, int position) {
|
|
|
+ public void move(float percent) {
|
|
|
+ this.percent = percent;
|
|
|
invalidate();
|
|
|
}
|
|
|
|
|
|
- public IntegralTaskPercentView initCustom(int position, String... titles) {
|
|
|
- invalidate();
|
|
|
- return this;
|
|
|
- }
|
|
|
}
|