摘要:本文将带你了解Android应用开发Android 自定义view之圆盘进度条,希望本文对大家学Android有所帮助。
本文将带你了解Android应用开发Android 自定义view之圆盘进度条,希望本文对大家学Android有所帮助。
很久没有用到自定义View了,手有点生疏了,这不同事刚扔给一个活,按照UI的要求,画一个进度条,带动画效果的。需求是这样的:这里写图片描述
嗯,实现后效果如下:
这里写图片描述
嗯,算是基本满足需求吧。
本文包含的知识点
1、自定义view的绘制
2、属性动画
3、图像的合成模式 PorterDuff.Mode
嗯,废话不多说,show me the code
1)WordView.java
<code>import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Xfermode;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
/**
* Author: gongwq on 2017/12/20 002011.
* Email: gwq_0111@163.com
* Descriptions:
*/
public class WordView extends View {
private Paint linePaint, circlePaint, circlePaintBg;
private Paint textPaint1, textPaint2, textPaint3, textPaint4;
private int screenWidth, screenHeight;
private int mCenter, mRadius;
private RectF mRectF, mRectFBg1, mRectFBg2;
private int defaultValue;
private float rate = 0f;
private String hasStudyText = ;
private String notStudyText = ;
private int startAng = 0;
private int defaultStartAng = 120;
private long animDuration = 2000L;
private int progressColor, wordTitleColor, wordViewBackground;
private Xfermode xfermode;
public WordView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
TypedArray ta = context.obtainStyledAttributes(
attrs, R.styleable.WordView);
progressColor = ta.getColor(R.styleable.WordView_progressColor, 0xFFFFFFFF);
wordViewBackground = ta.getColor(R.styleable.WordView_wordViewBackground, 0xFFFF0000);
wordTitleColor = ta.getColor(R.styleable.WordView_wordTitleColor, 0xFFFF00FF);
ta.recycle();
initPaint(context);
}
private void initPaint(Context context) {
screenWidth = MeasureUtil.getScreenWidth(context);
screenHeight = MeasureUtil.getScreenHeight(context);
linePaint = new Paint();
linePaint.setColor(Color.WHITE);
linePaint.setStyle(Paint.Style.FILL);
linePaint.setAntiAlias(true);
linePaint.setStrokeWidth(6.0f);
circlePaint = new Paint();
circlePaint.setColor(progressColor);
circlePaint.setAntiAlias(true);
circlePaint.setStyle(Paint.Style.STROKE);
circlePaint.setStrokeCap(Paint.Cap.ROUND);
circlePaint.setStrokeWidth(6.0f);
circlePaintBg = new Paint();
circlePaintBg.setColor(wordViewBackground);
circlePaintBg.setAntiAlias(true);
circlePaintBg.setStyle(Paint.Style.FILL);
textPaint1 = new Paint();//已学习生词
textPaint1.setColor(wordTitleColor);
textPaint1.setTextAlign(Paint.Align.CENTER);
textPaint1.setAntiAlias(true);
textPaint1.setTextSize(25);
textPaint2 = new Paint();//xx个
textPaint2.setColor(Color.WHITE);
textPaint2.setTextAlign(Paint.Align.CENTER);
textPaint2.setAntiAlias(true);
textPaint2.setTextSize(70);
textPaint4 = new Paint();//个
textPaint4.setColor(Color.WHITE);
textPaint4.setTextAlign(Paint.Align.CENTER);
textPaint4.setAntiAlias(true);
textPaint4.setTextSize(25);
textPaint3 = new Paint();//未学习生词x个
textPaint3.setColor(wordTitleColor);
textPaint3.setTextAlign(Paint.Align.CENTER);
textPaint3.setAntiAlias(true);
textPaint3.setTextSize(25);
mCenter = screenWidth / 2;
mRadius = screenWidth / 4;
mRectF = new RectF(10, 10, 2 * mRadius - body{ }
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号