2012-02-14 58 views

回答

2

我在代码中使用TextView来完成此操作,但是您可以使用ImageView更改文本视图。

我的TextView是一个横跨顶部的小条,因此参数发生了变化。

 params = new LinearLayout.LayoutParams(
       LinearLayout.LayoutParams.FILL_PARENT, 
      LinearLayout.LayoutParams.WRAP_CONTENT); 

     LinearLayout layout = new LinearLayout(this); 
     layout.setOrientation(LinearLayout.VERTICAL); 

     TextView tv = new TextView(this); 
     ourSurfaceView = new SurfGame(this); 

     testbox = new LinearLayout.LayoutParams(widthx,heighty/30); 
    layout.addView(tv,testbox); 
    layout.addView(ourSurfaceView,params); 
    setContentView(layout); 
3

不,您不能将子女Views添加到SurfaceView

你可以把两者的ImageView和其他一些容器SurfaceView,以及某些容器(RelativeLayoutFrameLayout)让后面的孩子漂浮在早期儿童(Z轴顺序)的顶部。因此,您可以通过这种方式在SurfaceView中给出ImageView的视觉外观。

+0

有没有办法做到这一点在代码我会感谢您的帮助。 – 2012-02-15 21:15:11

+1

@ toggy-tog-togs:将'SurfaceView'放入'RelativeLayout'中。然后,在运行时,只需使用适当的RelativeLayout.LayoutParams调用RelativeLayout上的'addView()'来添加'ImageView'。 – CommonsWare 2012-02-15 21:44:39

+0

感谢您的帮助 – 2012-02-15 22:04:49