
public BootStepView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// 加载自定义属性集合BootStepView
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BootStepView);
// 解析集合中的属性属性
// 将解析的属性传入到画圆的画笔颜色变量当中(本质上是自定义画圆画笔的颜色)
// 第二个参数是默认设置颜色(即无指定情况下使用)
circularColor = typedArray.getColor(R.styleable.BootStepView_circular_color, Color.RED);
circularSize=typedArray.getDimensionPixelSize(R.styleable.BootStepView_circular_size,16);
circularTextSize=typedArray.getDimensionPixelSize(R.styleable.BootStepView_circular_text_size,60);
circularTextColor= typedArray.getColor(R.styleable.BootStepView_circular_text_color, Color.WHITE);
....
}
在onMeasure()对View的宽高进行测量
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// 获取宽-测量规则的模式和大小
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
// 获取高-测量规则的模式和大小
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int width=480;
int height=240;
if (widthMode == MeasureSpec.AT_MOST && heightMode == MeasureSpec.AT_MOST) {
setMeasuredDimension(width, height);
} else if (widthMode == MeasureSpec.AT_MOST ) {
setMeasuredDimension(width, heightSize);
}else if(heightMode== MeasureSpec.AT_MOST){
setMeasuredDimension(widthSize, height);
}
}
## 在onDraw()实现
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 获取传入的padding值
final int paddingLeft = getPaddingLeft();
final int paddingRight = getPaddingRight();
final int paddingTop = getPaddingTop();
final int paddingBottom = getPaddingBottom();
int width=getWidth();
//开始绘制第一个圆
int oneX=paddingLeft+circularSize*2;
canvas.drawCircle(oneX,paddingTop,circularSize,paint);
//开始绘制数字1
paint.setColor(circularTextColor);
paint.setTextSize(circularTextSize);
canvas.drawText("1",oneX-circularTextSize/3,paddingTop+circularTextSize/3,paint);
//开始绘制第一个线条
paint.setColor(isTwoColor?circularColor:defaultColor);
canvas.drawLine(oneX+circularSize,paddingTop,width/2-circularSize,paddingTop,paint);
...
}
android模仿汽车之家对比车型效果源码
Android开发适用于的简单教学大纲视图
Android强大的超级文本视图
android 实现类似爱奇艺视频能够拖拽的视图效果
Android开发仿美团app头部左右切换视图效果
android开发银行卡操作步骤视图
Android多种下拉刷新效果,上拉加载更多,可配置自定义头部广告
Android开发中viewpager与视差页面一起,垂直滑动(或点击)和活
Android定义一个LoadViewHelper所有界面通用,切换加载中,加载
Android多种图片展示效果ZoomPreviewPicture
Android开发三步实现控件悬浮效果
android开发40余种实时滤镜相机图片修改美化源码
android模仿汽车之家对比车型效果源码
Android开发适用于的简单教学大纲视图
Android强大的超级文本视图
android 实现类似爱奇艺视频能够拖拽的视图效果
Android开发仿美团app头部左右切换视图效果
Android多种下拉刷新效果,上拉加载更多,可配置自定义头部广告
热门源码