将文本视图添加到曲面视图

chA*_*Ami 3 layout android textview surfaceview

我在我的应用程序中使用它作为表面视图,现在我想以编程方式添加文本视图.我怎样才能做到这一点.

"<com.csfcse.udrawer.UdrawerDrawingSurface
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:id="@+id/drawingSurface" 
        android:layout_gravity="left" />"
Run Code Online (Sandbox Code Playgroud)

谢谢......

Rib*_*ibo 16

一个选项可能是让FrameLayout有两个子节点,首先是SurfaceView,然后是你想要在SurfaceView上叠加的任何内容.在下面的示例中,FrameLayout中的第二个视图是带有Button和TextView的horozontil LinearLayout.FrameLayout将所有子项显示为按Z顺序堆叠,第一个子项位于底部,所有子项位于左上角.在这种情况下,LinearLayout具有Gravity.CENTER_VERTICAL(我认为你可以在LinearLayout上使用填充做同样的事情.

我从来没有找到关于SurfaceViews(或任何屏幕绘图)如何工作的很多(好)文档.闪烁或刷新可能有问题,但我在Froyo Evo上看不到太多问题.(此测试应用程序在Button和TextView下方的SurfaceView上绘制'旋转'线.

SurfaceView与视图覆盖它

如果问题很简单:如何以编程方式将TextView添加到由XML膨胀的布局创建的布局中,然后获取对布局实例的引用并向其调用addView().

Layout lay = parentLayo.findViewById(R.id.drawingSurfaceParent);
TextView tv = new TextView(this);
tv.setText("New textview");
lay.addView(tv);
Run Code Online (Sandbox Code Playgroud)


McS*_*tch 7

您需要使用Canvas和相应的文本绘制方法:

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