将文本视图添加到表面视图
我在应用程序中使用它作为表面视图,现在我想以编程方式向其添加文本视图。我该怎么办呢。
"<com.csfcse.udrawer.UdrawerDrawingSurface
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/drawingSurface"
android:layout_gravity="left" />"
谢谢......
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......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种选择可能是让 FrameLayout 具有两个子级,第一个是 SurfaceView,然后是您想要覆盖在 SurfaceView 上的任何内容。在下面的示例中,FrameLayout 中的第二个 View 是一个带有 Button 和 TextView 的 horozontil LinearLayout。 FrameLayout 将其所有子项显示为按 Z 顺序堆积,第一个子项位于底部,所有子项位于左上角。在这种情况下,LinearLayout 有 Gravity.CENTER_VERTICAL (我认为你可以在 LinearLayout 上使用填充做同样的事情。
我从来没有找到太多(好的)关于 SurfaceViews(或任何屏幕绘图)如何工作的文档。可能有闪烁或刷新问题,但我在 Froyo Evo 上没有看到太多问题。(此测试应用程序在 Button 和 TextView 下方的 SurfaceView 上绘制“旋转”线。
如果问题很简单:如何以编程方式将 TextView 添加到由 XML 膨胀布局创建的布局,然后获取对 Layout 实例的引用并调用 addView() 。
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.
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.
您需要使用 Canvas 和相应的文本绘制方法:
drawText(字符串文本, int 索引, int 计数, float x, float y, Paint 油漆)。
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).
这是不可能的,一个SurfaceView不能包含其他View。
This is not possible, a SurfaceView cannot contain other Views.