2013-07-05 70 views
1

我有一個名爲MyBringBackSurface SurfaceView,並構造是:如何製作SurfaceView透明背景?

public MyBringBackSurface(Context context) { 
     // TODO Auto-generated constructor stub 
     super(context); 
     setBackgroundResource(R.drawable.background); 
    } 

背景顯示出來,但如何使它透明,因此在它的前面顯示其他位圖?

+0

surfaceview.getHolder()setFormat(PixelFormat.TRANSLUCENT)的東西。 你有試過嗎? – NoobMe

回答

0

使用Color.TRANSPARENT作爲Surfaceview的背景顏色。

如果你想顯示在表面視圖位圖,你可以嘗試像下面的xml

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center"> 
    <SurfaceView 
     android:id="@+id/cameraSurface" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <ImageView 
       android:id="@+id/IV_MASK" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/mask" 
       android:background="@android:color/transparent" 
       /> 
    </RelativeLayout> 
+0

我試過了 我寫道:setBackgroundColor(Color.TRANSPARENT);對 ? 背景已經消失@AAnkit –

+0

這就是你在問題中提到的,使表面視圖變得透明。請清楚你的問題? – AAnkit

+0

我的意思是我嘗試了你告訴我但它沒有工作我很抱歉 –