programing

SurfaceView를 투명하게 만드는 방법

nasanasas 2020. 10. 4. 11:29
반응형

SurfaceView를 투명하게 만드는 방법


안녕하세요, 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가 다른 surfaceView 위에 배치되지만 여전히 창 뒤에 있으므로 Surface 뷰 위에 다른 보이는 뷰를 추가 할 수 있습니다.


DrawingSurface 및 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.


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

참고URL : https://stackoverflow.com/questions/5391089/how-to-make-surfaceview-transparent

반응형