【问题标题】:Adding text view to surface view将文本视图添加到表面视图
【发布时间】:2011-06-08 12:35:03
【问题描述】:

我在我的应用程序中使用这个表面视图,现在我想以编程方式向它添加文本视图。我该怎么做。

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

谢谢......

【问题讨论】:

    标签: android layout textview surfaceview


    【解决方案1】:

    这是不可能的,一个 SurfaceView 不能包含其他 View。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 是否可以使用这种方法使文本可编辑?
      【解决方案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() 。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-06
        • 1970-01-01
        • 2011-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多