Sunil Pandey
Sunil Pandey

Reputation: 7102

how to make surfaceview transparent

Hello all i want to make my DrawingSurface view transparent. i tried many thing but it's not working.

Here is my xml code to make my surface view transparent

<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>

Upvotes: 91

Views: 67183

Answers (4)

Mikael Holmberg
Mikael Holmberg

Reputation: 101

sfvTrack.setZOrderOnTop(true); 

will place the surfaceView on top of the window, meaning you cannot add items on top of the surfaceView.

If you want to add views on top of the surface view; you should consider using:

setZOrderMediaOverlay(true);

instead. This places this surfaceView on top of other surfaceViews, but still behind the window, allowing you to add other visible views on top of the surface view.

Upvotes: 10

TantanQi
TantanQi

Reputation: 2354

Try this in the constructor:

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

Upvotes: 233

VJ V&#233;lan Solutions
VJ V&#233;lan Solutions

Reputation: 6554

TexttureView will be better for your needs than SurfaceView, i believe.

Upvotes: 5

slund
slund

Reputation: 6397

Is your DrawingSurface and extension of SurfaceView?

There is no way to get a SurfaceView to do what you are wanting it to do. The mechanics of the surface view are such that it can not have anything visible behind it. (see the answer here http://groups.google.com/group/android-developers/browse_thread/thread/8d88ef9bb22da574)

I tested your hierarchy with a custom view extending SurfaceView and I see your problem. If I switch to a custom view that simply extends View, I can get transparency.

Upvotes: 6

Related Questions