android - Draw auto adjustable text infront of bitmap -
i want draw text in front of marker image.but text going out of boundary of image.can auto adjust text? if yes please give me example pragmatically. using following code draw text.
paint.settextsize((int) (11 * scale)); // text shadow paint.setshadowlayer(1f, 0f, 1f, color.white); // draw text canvas center rect bounds = new rect(); paint.settextalign(align.center); paint.gettextbounds(gtext, 0, gtext.length(), bounds); int x=20; int y=15; canvas.drawtext(gtext, x * scale, y * scale, paint);
it show following output
how can adjust text?
private textpaint mtp; private string mtext; private final static float text_size = 30; private void drawingsettings() { mtp = new textpaint(paint.anti_alias_flag); mtp.setstyle(paint.style.fill); mtp.setcolor(0xffcccccc); mtp.settextsize(text_height); mtext = "some text" } @override public void ondraw(canvas canvas) { int bmpwidth = mbitmap.getwidth(); int textwidth = mtp.mesuretext(mtext); float textsize = text_size; while(mtp.mesuretext(text)>bmpwidth) { textsize-1; mtp.settextsize(textsize); } float xpos = 0; float ypos = 0; canvas.drawtext(mtext,xpos,ypos,mtp); }
note, when optimizing should consider moving text size calculation outside ondraw function.
Comments
Post a Comment