简体   繁体   English

如何使surfaceview透明

[英]how to make surfaceview transparent

Hello all i want to make my DrawingSurface view transparent. 大家好我想让我的DrawingSurface视图透明。 i tried many thing but it's not working. 我试了很多东西,但它不起作用。

Here is my xml code to make my surface view transparent 这是我的表面视图透明的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>

Try this in the constructor: 在构造函数中尝试这个:

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

will place the surfaceView on top of the window, meaning you cannot add items on top of the surfaceView. 将surfaceView放在窗口顶部,这意味着您无法在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. 这会将此surfaceView放在其他surfaceViews的顶部,但仍然在窗口后面,允许您在曲面视图的顶部添加其他可见视图。

我相信TexttureView会比SurfaceView更好地满足您的需求。

Is your DrawingSurface and extension of SurfaceView? 是您的DrawingSurface和SurfaceView的扩展吗?

There is no way to get a SurfaceView to do what you are wanting it to do. 无法让SurfaceView执行您希望它执行的操作。 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 ) (请参阅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. 我使用扩展SurfaceView的自定义视图测试了您的层次结构,我看到了您的问题。 If I switch to a custom view that simply extends View, I can get transparency. 如果我切换到只扩展View的自定义视图,我可以获得透明度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM