Skip to content

Instantly share code, notes, and snippets.

@raghunandankavi2010
Created November 9, 2018 16:28
Show Gist options
  • Save raghunandankavi2010/3399c08591ef8104a627bd3aefadef07 to your computer and use it in GitHub Desktop.
Save raghunandankavi2010/3399c08591ef8104a627bd3aefadef07 to your computer and use it in GitHub Desktop.
labels without rounded rect
private void drawLabels(Canvas canvas) {
weekWidth = (getWidth () - getPaddingLeft () - getPaddingRight ()) / weeksCount;
graphHeight = getHeight () - getPaddingTop () - getPaddingBottom ();
float centerX = getPaddingLeft() + (weekWidth/2);
for(int i=0;i<weeksCount;i++) {
String week = "week "+i;
mTextPaint.getTextBounds(week, 0, week.length(), textBounds);
int mTextWidth = Math.round(mTextPaint.measureText(week)); // Use measureText to calculate width
int mTextHeight = textBounds.height(); // Use height from getTextBounds()
canvas.drawText(week, centerX - (mTextWidth / 2), (getHeight() - getPaddingBottom()) + 100, mTextPaint);//100 hardcoded
centerX = centerX+ (weekWidth);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment