|
@@ -340,54 +340,59 @@ public class DoubleSlideSeekBar extends View {
|
|
|
@Override
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
super.onDraw(canvas);
|
|
|
- // Y轴 坐标
|
|
|
- lineY = getHeight() - paddingBottom - bitmapHeight / 2;
|
|
|
- // 字所在高度 100$
|
|
|
-// textHeight = lineY - bitmapHeight / 2 - 10;
|
|
|
- textHeight = lineY - bitmapHeight / 2 - 20;
|
|
|
- //是否画刻度
|
|
|
- if (hasRule) {
|
|
|
- drawRule(canvas);
|
|
|
- }
|
|
|
- if (linePaint == null) {
|
|
|
- linePaint = new Paint();
|
|
|
- }
|
|
|
- //画内部线
|
|
|
- linePaint.setAntiAlias(true);
|
|
|
- linePaint.setStrokeWidth(lineWidth);
|
|
|
- linePaint.setColor(inColor);
|
|
|
- linePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
- canvas.drawLine(slideLowX, lineY, slideBigX, lineY, linePaint);
|
|
|
- linePaint.setColor(outColor);
|
|
|
- linePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
- //画 外部线
|
|
|
- canvas.drawLine(lineStart, lineY, slideLowX, lineY, linePaint);
|
|
|
- canvas.drawLine(slideBigX, lineY, lineEnd, lineY, linePaint);
|
|
|
- //画游标
|
|
|
- if (bitmapPaint == null) {
|
|
|
- bitmapPaint = new Paint();
|
|
|
- }
|
|
|
- canvas.drawBitmap(bitmapLow, slideLowX - bitmapWidth / 2, lineY - bitmapHeight / 2, bitmapPaint);
|
|
|
- canvas.drawBitmap(bitmapBig, slideBigX - bitmapWidth / 2, lineY - bitmapHeight / 2, bitmapPaint);
|
|
|
- //画 游标上边的字
|
|
|
- if (textPaint == null) {
|
|
|
- textPaint = new Paint();
|
|
|
- }
|
|
|
- textPaint.setColor(textColor);
|
|
|
- textPaint.setTextSize(textSize);
|
|
|
- textPaint.setAntiAlias(true);
|
|
|
-
|
|
|
- //这里不要直接转int 因为会去掉小数位 和实际显示的不符合 要转string 四舍五入
|
|
|
- Log.e(TAG, "smallRange " + Integer.parseInt(String.format("%.0f", smallRange)));
|
|
|
- Log.e(TAG, "bigRange " + Integer.parseInt(String.format("%.0f", bigRange)));
|
|
|
-// canvas.drawText(String.format("%.0f" + unit, smallRange), slideLowX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
-// canvas.drawText(String.format("%.0f" + unit, bigRange), slideBigX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
|
|
|
- Log.e(TAG, "smallRange算出来的 " + computRange(slideLowX));
|
|
|
- Log.e(TAG, "bigRange算出来的" + computRange(slideBigX));
|
|
|
-
|
|
|
- canvas.drawText(time[Integer.parseInt(String.format("%.0f", smallRange)) - 1], slideLowX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
- canvas.drawText(time[Integer.parseInt(String.format("%.0f", bigRange)) - 1], slideBigX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
+ try {
|
|
|
+ // Y轴 坐标
|
|
|
+ lineY = getHeight() - paddingBottom - bitmapHeight / 2;
|
|
|
+ // 字所在高度 100$
|
|
|
+ //textHeight = lineY - bitmapHeight / 2 - 10;
|
|
|
+ textHeight = lineY - bitmapHeight / 2 - 20;
|
|
|
+ //是否画刻度
|
|
|
+ if (hasRule) {
|
|
|
+ drawRule(canvas);
|
|
|
+ }
|
|
|
+ if (linePaint == null) {
|
|
|
+ linePaint = new Paint();
|
|
|
+ }
|
|
|
+ //画内部线
|
|
|
+ linePaint.setAntiAlias(true);
|
|
|
+ linePaint.setStrokeWidth(lineWidth);
|
|
|
+ linePaint.setColor(inColor);
|
|
|
+ linePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ canvas.drawLine(slideLowX, lineY, slideBigX, lineY, linePaint);
|
|
|
+ linePaint.setColor(outColor);
|
|
|
+ linePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ //画 外部线
|
|
|
+ canvas.drawLine(lineStart, lineY, slideLowX, lineY, linePaint);
|
|
|
+ canvas.drawLine(slideBigX, lineY, lineEnd, lineY, linePaint);
|
|
|
+ //画游标
|
|
|
+ if (bitmapPaint == null) {
|
|
|
+ bitmapPaint = new Paint();
|
|
|
+ }
|
|
|
+ canvas.drawBitmap(bitmapLow, slideLowX - bitmapWidth / 2, lineY - bitmapHeight / 2, bitmapPaint);
|
|
|
+ canvas.drawBitmap(bitmapBig, slideBigX - bitmapWidth / 2, lineY - bitmapHeight / 2, bitmapPaint);
|
|
|
+ //画 游标上边的字
|
|
|
+ if (textPaint == null) {
|
|
|
+ textPaint = new Paint();
|
|
|
+ }
|
|
|
+ textPaint.setColor(textColor);
|
|
|
+ textPaint.setTextSize(textSize);
|
|
|
+ textPaint.setAntiAlias(true);
|
|
|
+
|
|
|
+ //这里不要直接转int 因为会去掉小数位 和实际显示的不符合 要转string 四舍五入
|
|
|
+ Log.e(TAG, "smallRange " + Integer.parseInt(String.format("%.0f", smallRange)));
|
|
|
+ Log.e(TAG, "bigRange " + Integer.parseInt(String.format("%.0f", bigRange)));
|
|
|
+ //canvas.drawText(String.format("%.0f" + unit, smallRange), slideLowX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
+ //canvas.drawText(String.format("%.0f" + unit, bigRange), slideBigX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
+
|
|
|
+ Log.e(TAG, "smallRange算出来的 " + computRange(slideLowX));
|
|
|
+ Log.e(TAG, "bigRange算出来的" + computRange(slideBigX));
|
|
|
+
|
|
|
+ canvas.drawText(time[Integer.parseInt(String.format("%.0f", smallRange)) - 1], slideLowX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
+ canvas.drawText(time[Integer.parseInt(String.format("%.0f", bigRange)) - 1], slideBigX - bitmapWidth / 2, textHeight, textPaint);
|
|
|
+ } catch (Exception e) {
|
|
|
+ //
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|