I am working on a android app in which I display some text in japanies using TextView. In addition to the text, I want to show some annotations on top of certain characters in the text (ruby annotation - https://en.wikipedia.org/wiki/Ruby_character). My research did not show any inbuilt API's from Android to support ruby annotation. So I am trying custome drawText() method to write text and annotations on to a canvas. In drawText() I am writing each character to certain (x,y) position with variable font size for main text and annotation text.
Since I am determining the (x,y) position of each char, Now the dimensions of the textView became tricky. Some times, the main text maybe very large. The way I am calculating the Width and Height of textView is Width = paint.measureText(length if longest text line (In case of multiple lines rendering); Height = Number of lines * font size.
// Setting the width of TextView
@Override public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, @Nullable Paint.FontMetricsInt fm) {
paint.setTextSize(util.getTextSize());
return (int) paint.measureText(text);
}
I am having trouble in how to set the height of textView?