android 带刻度的滑动条_Android自定义控件尺子 滚动刻度尺

自定义控件是件很有乐趣的事,慢慢的会爱上它,哈哈哈。废话不多说先上设计图

接下来我们我们要先分析一下页面中需要到哪些东西

1.一条无限长的底线;

2.一根在屏幕中间的红色标记线,代表当前位置;

3.一个半透明的蓝色背景,改背景超过部分才会被展现;

4.刻度 整数高一点刻度  非整第一点的刻度

5.一个大刻度上都会标的数值

6.滚动

接下来进入正题,让我们开始绘制:

首先我们先给控件定义它的属性,根据刚才的分析我给他定义了一下的属性

接下来在控件的构造方法中获取这些值,里面还涉及到一些需要初始化的值都有备注

public RulerView(Context context, AttributeSet attrs) {

super(context, attrs);

WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

DisplayMetrics dm = new DisplayMetrics();

windowManager.getDefaultDisplay().getMetrics(dm);

screenWidth = dm.widthPixels;

TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RulerView);

maxValue = typedArray.getDimensionPixelOffset(R.styleable.RulerView_max_value, 200000);

minValue = typedArray.getDimensionPixelOffset(R.styleable.RulerView_min_value, 0);

scaleTextSize = typedArray.getDimensionPixelOffset(R.styleable.RulerView_scale_text_size, 24);

scaleTextColor = typedArray.getColor(R.styleable.RulerView_scale_text_color, Color.parseColor("#d8d8d8"));

scaleSelectColor = typedArray.getColor(R.styleable.RulerView_scale_select_color, Color.parseColor("#76e4ff"));

scaleSelectBackgroundColor = typedArray.getColor(R.styleable.RulerView_scale_select_background_color, Color.parseColor("#6676e4ff"));

scaleUnSelectColor = typedArray.getColor(R.styleable.RulerView_scale_unselect_color, Color.parseColor("#d8d8d8"));

cursorColor = typedArray.getColor(R.styleable.RulerView_tag_col

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值