簡體   English   中英

如何使surfaceview透明

[英]how to make surfaceview transparent

大家好我想讓我的DrawingSurface視圖透明。 我試了很多東西,但它不起作用。

這是我的表面視圖透明的xml代碼

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/icon" >
        </ImageView>

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#00000000" >

            <codewalla.android.drawings.DrawingSurface
                android:id="@+id/drawingSurface"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </codewalla.android.drawings.DrawingSurface>
        </LinearLayout>
    </FrameLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/colorRedBtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="10"
            android:onClick="onClick"
            android:text="R" />

        <Button
            android:id="@+id/colorBlueBtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="10"
            android:onClick="onClick"
            android:text="G" />

        <Button
            android:id="@+id/colorGreenBtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="10"
            android:onClick="onClick"
            android:text="B" />

        <Button
            android:id="@+id/undoBtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="10"
            android:onClick="onClick"
            android:text="U" />

        <Button
            android:id="@+id/redoBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="10"
            android:onClick="onClick"
            android:text="R" />
    </LinearLayout>

</RelativeLayout>

在構造函數中嘗試這個:

SurfaceView sfvTrack = (SurfaceView)findViewById(R.id.sfvTrack);
sfvTrack.setZOrderOnTop(true);    // necessary
SurfaceHolder sfhTrackHolder = sfvTrack.getHolder();
sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT);
sfvTrack.setZOrderOnTop(true); 

將surfaceView放在窗口頂部,這意味着您無法在surfaceView頂部添加項目。

如果要在曲面視圖的頂部添加視圖; 你應該考慮使用:

setZOrderMediaOverlay(true);

代替。 這會將此surfaceView放在其他surfaceViews的頂部,但仍然在窗口后面,允許您在曲面視圖的頂部添加其他可見視圖。

我相信TexttureView會比SurfaceView更好地滿足您的需求。

是您的DrawingSurface和SurfaceView的擴展嗎?

無法讓SurfaceView執行您希望它執行的操作。 表面視圖的機制使得它后面不能有任何可見的東西。 (請參閱http://groups.google.com/group/android-developers/browse_thread/thread/8d88ef9bb22da574上的答案)

我使用擴展SurfaceView的自定義視圖測試了您的層次結構,我看到了您的問題。 如果我切換到只擴展View的自定義視圖,我可以獲得透明度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM