亲们里面的线段颜色和节点图标都是可以自定义的。
在没给大家分享实例代码之前,先给大家展示下效果图:
main.xml
attrs.xml
MutiProgress.java
package com.demo.demomutiprogress;
import java.util.ArrayList;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class MutiProgress extends View{
private int nodesNum ; //节点数量
private Drawable progressingDrawable; //进行中的图标
private Drawable unprogressingDrawable;
private Drawable progresFailDrawable; //失败的节点
private Drawable progresSuccDrawable; //成功的节点
private int nodeRadius; //节点的半径
private int processingLineColor; //进度条的颜色
// private int progressLineHeight; //进度条的高度
private int currNodeNO; //当前进行到的节点编号。从0开始计算
private int currNodeState; //当前进行到的节点编号所对应的状态 0:失败 1:成功
// private int textSize; //字体大小
Context mContext;
int mWidth,mHeight;
private Paint mPaint;
private Canvas mCanvas;
private Bitmap mBitmap; //mCanvas绘制在这上面
private ArrayList nodes;
private int DEFAULT_LINE_COLOR = Color.BLUE;
public MutiProgress(Context context) {
this(context,null);
}
public MutiProgress(Context context, AttributeSet attrs) {
this(context,attrs,0);
}
public MutiProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
TypedArray mTypedArray = context.obtainStyledAttributes(attrs,R.styleable.MutiProgress);
nodesNum = mTypedArray.getInteger(R.styleable.MutiProgress_nodesNum, 1); //默认一个节点
nodeRadius = mTypedArray.getDimensionPixelSize(R.styleable.MutiProgress_nodeRadius, 10); //节点半径
progressingDrawable = mTypedArray.getDrawable(R.styleable.MutiProgress_progressingDrawable);
unprogressingDrawable = mTypedArray.getDrawable(R.styleable.MutiProgress_unprogressingDrawable);
progresFailDrawable = mTypedArray.getDrawable(R.styleable.MutiProgress_progresFailDrawable);
progresSuccDrawable = mTypedArray.getDrawable(R.styleable.MutiProgress_progresSuccDrawable);
processingLineColor = mTypedArray.getColor(R.styleable.MutiProgress_processingLineColor, DEFAULT_LINE_COLOR);
currNodeState = mTypedArray.getInt(R.styleable.MutiProgress_currNodeState, 1);
currNodeNO = mTypedArray.getInt(R.styleable.MutiProgress_currNodeNO, 1);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mWidth = getMeasuredWidth();
mHeight = getMeasuredHeight();
mBitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
mPaint = new Paint();
mPaint.setColor(processingLineColor);
mPaint.setAntiAlias(true);
mPaint.setStrokeJoin(Paint.Join.ROUND); // 圆角
mPaint.setStrokeCap(Paint.Cap.ROUND); // 圆角
mCanvas = new Canvas(mBitmap);
nodes = new ArrayList();
float nodeWidth = ((float)mWidth)/(nodesNum-1);
for(int i=0;i
源码下载点击此处
以上所述是小编给大家介绍的Android自定义多节点进度条显示的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!



