2012-02-14 60 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