I am trying several ways to center 3 lines of text on a clock and seem to be unable to figure this out. New guard jewelry services require you to draw on canvas. I initialize the text offset by grabbing the length of the text of each line and dividing by 2.
mXDateOffset = mTextDateColorPaint.measureText("May 21, 2015") /2; mXTimeOffset = mTextTimeColorPaint.measureText("12:00:00")/2; mXBatteryOffset = mTextBatteryColorPaint.measureText("99%") /2 ;
Then, when I set the text and drawing elements to the canvas, I find the center of the rectangle (screen) minus the screen to find the starting position of the text.
canvas.drawText( timeText, bounds.centerX() - mXTimeOffset, 40.0f, mTextTimeColorPaint ); canvas.drawText( date, bounds.centerX() - mXDateOffset, 90.0f, mTextDateColorPaint); canvas.drawText( mBatteryLevel, bounds.centerX() - mXBatteryOffset, 130.0f, mTextBatteryColorPaint );
What I get is ...

Not sure what else to do.
android android-wear android-service
Jpg
source share