Auto Adjust Textview Android -
i found code resize text based on height of textview.source, not getting how pass text in function,my text cmoing intent
public int getheightofmultilinetext(string text,int textsize, int maxwidth) { textpaint paint = new textpaint(); paint.settextsize(textsize); int index = 0; int linecount = 0; while(index < text.length()) { index += paint.breaktext(text,index,text.length(),true,maxwidth,null); linecount++; } rect bounds = new rect(); paint.gettextbounds("yy", 0, 2, bounds); // obtain space between lines double linespacing = math.max(0,((linecount - 1) * bounds.height()*0.25)); return (int)math.floor(linespacing + linecount * bounds.height()); }
well can text of textview string using urtextview.gettext().tostring()
textview urtextview; string text = urtextview.gettext().tostring(); int textsize = 100; int maxheight = 50; while(getheightofmultilinetext(text,textsize,maxwidth) > maxheight) textsize--;
this should work.
Comments
Post a Comment