{
    分享网正式开通,我们为大家提供免费资源,欢迎大家踊跃投稿!

android开发银行卡操作步骤视图

继承View 实现自定义属性(不知道自定义属性的百度)

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);
...
}

资源均来自第三方,谨慎下载,前往第三方网站下载


米微资源分享网 , 版权所有丨本站资源仅限于学习研究,严禁从事商业或者非法活动!丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:android开发银行卡操作步骤视图
喜欢 ()分享 (0)