Android - create TextView (or EditText) programmatically and set it in a specific place on the screen giving coordinates -
i building android app user paints objects in screen. 1 type of object text object. user creates object dragging finger , object shown rectangle can moved/reshaped. when user taps text object, launch new activity user enters text return on onactivityresult method.
now want show text in object. can have access stuff coordinates of rectangle etc text class. want in essence, create textview (or edittext) programmatically , set bounds bounds of rectangle object painted in. there method can me it?
(another approach use canvas.drawtextonpath method in text object. seems more complicated since text might out of object, , have handle multilines)
thank in advance!
edit: trying gama's approach
protected void onactivityresult(int requestcode, int resultcode, intent data) { switch(requestcode) { case 1: if (resultcode == activity.result_ok) { string text=data.getstringextra("text"); system.out.println(text); textview tv=new textview(this); //layoutparams lp = new layoutparams(new viewgroup.marginlayoutparams((int)texts.get(index).width,(int)texts.get(index).height)); layoutparams lp = new layoutparams(new viewgroup.marginlayoutparams(100,100)); //tv.setlayoutparams(lp); //lp.setmargins((int)texts.get(index).sx, (int)texts.get(index).sy, (int)texts.get(index).lx, (int)texts.get(index).ly); tv.setlayoutparams(lp); tv.settextsize(10); tv.settextcolor(color.red); tv.settext(text); lp.setmargins(0,0,0,0); //tv.setvisibility(view.visible); system.out.println("got "+tv.gettext()); } break; } } both prints show text expected not see in screen (tried set on bottom left begin with)
actually, drawtextonpath best bet. won't bleed out. have create path goes left, center vertical of rectangle right center vertical. method take care of resizing text stay within path.
you can adjust path accordingly using paint.gettextwidth(). if width bigger box, extend path line paint.gettextheight() below first line.
Comments
Post a Comment