如何设置多个SurfaceView的Z顺序

时间:2013-08-07 18:12:33

标签: android user-interface surfaceview

我有SurfaceView作为相机的实时预览,GLSurfaceView用于绘制一些OpenGL对象,最后SurfaceView用于显示一些GUI元素。我试图将GLSurfaceView放在相机的SurfaceView上,但同时我希望GUI的SurfaceView高于GLSurfaceView。我尝试了setZOrderOnTop函数,但它不能用于2 SurfaceView以上。有没有办法管理多个View s的Z顺序?

1 个答案:

答案 0 :(得分:2)

  

有没有办法管理多个视图的Z顺序?

步骤1:将它们放在支持Z轴排序的容器中,例如FrameLayoutRelativeLayout

步骤2:后来的孩子在Z轴上比早期孩子高,所以要对这些孩子进行适当的排序。

例如:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/big"
        android:textSize="120dip"
        android:textStyle="bold"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/small"/>

</RelativeLayout>

第二个按钮(android:text="@string/small")将浮动在第一个按钮的顶部。

现在,SurfaceViews是不寻常的野兽,如果你能让它们以你想要的方式工作,我会感到惊讶。如果您的android:minSdkVersion为14或更高,请考虑切换为TextureView