开发者

Adding text view to surface view

开发者 https://www.devze.com 2023-02-03 20:45 出处:网络
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.开发者_StackOverflow社区

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.开发者_StackOverflow社区

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

Thanks......


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.

Adding text view to surface view

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);


You'll need to use the Canvas and a corresponding text draw method:

drawText(String text, int index, int count, float x, float y, Paint paint).


This is not possible, a SurfaceView cannot contain other Views.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号