Calculation of the scale
-
I can't figure out how to roll the scale cycle. Figure it in customview:
public void onDraw(Canvas canvas){ startingPoint = mainPoint; counter = 0; for (int i = 1;; i++) { if (startingPoint > screenSize) { break; }
if(i % 4 == 0) { size = scaleHeight / 4; counter = counter + 1; } else { if(i % 2 == 0) { size = scaleHeight / 8; } else { size = scaleHeight / 16; } } canvas.drawLine(startingPoint, endPoint - size, startingPoint, endPoint, rulerPaint); if (i % 4 == 0) { String c = Integer.toString(counter); canvas.drawText(c, startingPoint, endPoint - (size + 20), textPaint); } startingPoint = startingPoint + pxmm;
}
I limit it to eleven long cases:
But I need an endless scale:
Let's say we can remove the counter value in the onDraw method, but how does it affect productivity? Even if I put his value 1,000, there's already a scrubbing.
Here's my onScroll:public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
mainPoint = mainPoint - distanceX;
invalidate();
return true;
}
And onMeasure:
protected void onMeasure(int w, int h) {
DisplayMetrics metrics = new DisplayMetrics(); ((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
h = metrics.heightPixels / 5;
w = metrics.widthPixels;setMeasuredDimension(w, h); scaleHeight = h; scaleWidth = w; screenSize = w; endPoint = h; midScreenPoint = w / 2; pxmm = screenSize / 28; }
How are such tasks carried out?
-
We need to draw a scale from the start of the screen to its end. The cycle should not be on the scale, but on the screen width. And in the cycle, we're running a scale meter as soon as it reaches 11, pushing.
Such an approach would make it easy to draw a scale with a shift, simply assigning the scale counter to it first and ready. Scrulling won't be necessary.