栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android自定义多节点进度条显示的实现代码(附源码)

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android自定义多节点进度条显示的实现代码(附源码)

亲们里面的线段颜色和节点图标都是可以自定义的。

在没给大家分享实例代码之前,先给大家展示下效果图:

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自定义多节点进度条显示的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/159447.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号