Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding text view to surface view

i use this a s surface view in my application and now i want to add text view to this programmatically. How can i do that.

"<com.csfcse.udrawer.UdrawerDrawingSurface
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:id="@+id/drawingSurface" 
        android:layout_gravity="left" />"

Thanks......

like image 966
chAmi Avatar asked Nov 28 '22 18:11

chAmi


1 Answers

An option may be to have a FrameLayout with two children, first the SurfaceView, then whatever you want to overlay on the SurfaceView. In the sample below, the second View in the FrameLayout is a horozontil LinearLayout with a Button and a TextView. The FrameLayout displays all its children as piled in Z order with the first child at the bottom and all children positioned at the upper left corner. In this case the LinearLayout has Gravity.CENTER_VERTICAL (I think you could do the same thing with padding on the LinearLayout.

I have never found much (good) documentation about how SurfaceViews (or any of the screen drawing) works. There may be a problem with flickering or refresh, but I don't see much problem on my Froyo Evo. (This test app draws 'twirling' lines on the SurfaceView below the Button and TextView.

SurfaceView with views overlaying it

If the question is simply: How do you programmatically add a TextView to a Layout that was created by a XML inflated Layout, then, get a reference to the Layout instance and call addView() to it.

Layout lay = parentLayo.findViewById(R.id.drawingSurfaceParent);
TextView tv = new TextView(this);
tv.setText("New textview");
lay.addView(tv);
like image 156
Ribo Avatar answered Nov 30 '22 06:11

Ribo