canvas - in android trying to create an image by taking the width and height of textview -


i have created layout , textview dynamically , set textview width value , hieght fill_parent.

while doing

    tv = new textview(this);     tv.setlayoutparams(new layoutparams(500, layoutparams.wrap_content));     tv.settext("hello world how whats whats hows life oh great");     tv.settextcolor(color.black);     tv.setbackgroundcolor(color.transparent);     tv.settextsize(24);     ll.addview(tv);     this.setcontentview(ll); 

its showing content nicely , wrapping correctly

hello world how whats whats hows life oh great

but when try extract textview width , height , try create image of same width , same height, generating smaller width image cutting correctly word y partially.

    bitmap = bitmap.createbitmap(tv.getwidth(),tv.getheight(),config.rgb_565);      canvas=new canvas(bitmap);     canvas.drawargb(255,0,255,0);             paint.setstyle(style.fill);     paint.setcolor(color.blue);     paint.setantialias(true);     paint.settypeface(typeface.serif);     paint.settextsize((int) 24);             canvas.drawtext(tv.gettext().tostring().substring(0,44),0,27, paint);     canvas.drawtext(tv.gettext().tostring().substring(tv.getlayout().getlinestart(1),tv.getlayout().getlinestart(2)),0,48, paint);     canvas.drawtext(tv.gettext().tostring().substring(tv.getlayout().getlinestart(2),tv.getlayout().getlinestart(3)),0,48+24, paint);     canvas.save(); 

whats problem.

i tried too

bitmap = bitmap.createbitmap(tv.getwidth(),tv.getheight(),config.rgb_565);         canvas=new canvas(bitmap);         canvas.drawargb(255,0,255,0);         final textpaint paint = new textpaint(color.blue);         paint.setstyle(style.fill);         paint.setantialias(true);         paint.settypeface(typeface.serif);         paint.settextsize((int) 24);         canvas.save();         staticlayout sl= new staticlayout(tv.gettext().tostring(), paint, bitmap.getwidth(), android.text.layout.alignment.align_normal, 1.0f, 0.0f, false);         sl.draw(canvas); 

but in result getting line cutting text , underline too. please advice

textviews word wrap. drawtext not, design. if need that, need use staticlayout wrapping.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -