设置Surface View的背景颜色

2023-12-29

我想为相机表面视图的表面视图设置背景颜色。

我在用this https://stackoverflow.com/questions/8104789/how-to-set-backgroundcolor-to-a-surfaceview-in-android用于实施相同的。但这个例子并不完整。谁能帮我提供一些其他有用的链接。

Thanks


有一个解决方法可以做到这一点。

  1. 为SurfaceView添加一个父ViewGroup,将背景颜色设置为该ViewGroup而不是SurfaceView;

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_dark">
    
        <com.example.surfacetest.MySurface
            android:id="@+id/surface"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </FrameLayout>
    
  2. 为 SurfaceView 实例添加以下内容;

    surfaceView.setZOrderOnTop(true);
    surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    

现在你得到了你想要的背景颜色,并且表面视图是半透明的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

设置Surface View的背景颜色 的相关文章

随机推荐