44 spot_on = BitmapFactory.decodeResource(getResources(),R.mipmap.img_setting_seekbar_thumbe); //这个是已经滑动过的界点的图标
45 bitMapHeight = thumb.getHeight()/2; //这里影响点中的图标的位置 这个正好 不用改
46 textMove = bitMapHeight+ 5; //xqx 这里参数大小要改,不是固定的,具体看项目效果
47 textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics()); //文字大小,第二个参数个人设置
48 circleRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics());
49 mPaint = new Paint(Paint.DITHER_FLAG);
50 mPaint.setAntiAlias(true);//锯齿不显示
51 mPaint.setStrokeWidth(3);
52 mTextPaint = new Paint(Paint.DITHER_FLAG);
53 mTextPaint.setAntiAlias(true);
54 mTextPaint.setTextSize(textSize);
55 mTextPaint.setColor(0xffb5b5b4);
56 buttonPaint = new Paint(Paint.DITHER_FLAG);
57 buttonPaint.setAntiAlias(true);
58
59 }
60 /**
61 * 实例化后调用,设置bar的段数和文字
62 */
63 public void initData(ArrayList<String> section){
64 if(section != null){
65 section_title = section;
66 }else {
67 //如果没有传入正确的分类级别数据,则默认使用“低”“中”“高”
68 String[] str = new String[]{"低", "中", "高"};
69 section_title = new ArrayList<String>();
70 for (int i = 0; i < str.length; i++) {
71 section_title.add(str[i]);
72 }
73 }
74 }
75
76 @Override
77 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
78 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
79
80 int widthMode = MeasureSpec.getMode(widthMeasureSpec);
81 int widthSize = MeasureSpec.getSize(widthMeasureSpec);
82 int heightMode = MeasureSpec.getMode(heightMeasureSpec);
83 int heightSize = MeasureSpec.getSize(heightMeasureSpec);
84
85 width = widthSize;
86 float scaleX = widthSize / 1080;
87 float scaleY = heightSize / 1920;
88 scale = Math.max(scaleX,scaleY);
89 //控件的高度
90 //height = 185;
91 height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 62, getResources().getDisplayMetrics());
92 setMeasuredDimension(width, height);
93 width = width-bitMapHeight/2;
94 perWidth = (width - section_title.size()*spot.getWidth() - thumb.getWidth()/2) / (section_title.size()-1);
95 hotarea = perWidth/2;
96 }
97
98 @Override
99 protected void onDraw(Canvas canvas) {
100 super.onDraw(canvas);
101 mPaint.setColor(Color.WHITE);
102 mPaint.setStyle(Paint.Style.FILL);
103 mPaint.setAlpha(0);
104 canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), mPaint);
105 canvas.drawBitmap(bitmap, 0, 0, null);
106 mPaint.setAlpha(255);
107 mPaint.setColor(colors[1]);
108 canvas.drawLine(bitMapHeight, height * 2 / 3, width - bitMapHeight - spot_on.getWidth() / 2, height * 2 / 3, mPaint);
109 int section = 0;
110 while(section < section_title.size()){
111 if(section < cur_sections) {
112 mPaint.setColor(colors[0]);
113 canvas.drawLine(thumb.getWidth()/2 + section * perWidth + (section+1) * spot_on.getWidth(),height * 2 / 3,
114 thumb.getWidth()/2 + section * perWidth + (section+1) * spot_on.getWidth() + perWidth,height * 2 / 3,mPaint);
115 canvas.drawBitmap(spot_on, thumb.getWidth()/2 + section * perWidth + section * spot_on.getWidth(),height * 2 / 3 - spot_on.getHeight()/2,mPaint);
116 }else{
117 mPaint.setAlpha(255);
118 if(section == section_title.size |