【问题标题】:SurfaceView on top of SurfaceViewSurfaceView 之上的 SurfaceView
【发布时间】:2015-05-06 13:52:09
【问题描述】:

我正在使用两个 MjpegView(扩展 SurfaceView 的自定义视图)构建应用程序。问题是有时我看不到第二个摄像头视图,因为它位于第一个摄像头视图后面。流式传输没有任何问题,我尝试更改布局内相机视图的位置但没有任何成功,还尝试将其放在前面(第二个相机)。

这是它自己的布局代码,

谢谢

  <?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"
    android:clickable="true"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/visul_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/camera_border"
        android:padding="2dp" >

        <TextView
            android:id="@+id/no_visu_stream"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/measurment_no_stream"
            android:textColor="@android:color/white"
            android:textSize="25sp" />

         <com.example.test.views.MjpegView
            android:id="@+id/sh_surface"
            android:layout_alignParentBottom="true"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:visibility="gone" />

        <com.example.test.views.MjpegView
            android:id="@+id/visul_surface"
            android:layout_width="match_parent"
            android:layout_margin="2dp"
            android:layout_height="500dp"
            android:visibility="gone" />

        <ImageView
            android:id="@+id/cible"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/cible"
            android:visibility="gone" />


        <TextView
            android:id="@+id/no_sh_stream"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerInParent="true"
            android:text="@string/measurment_no_stream"
            android:textColor="@android:color/white"
            android:textSize="14sp" />



    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/eye_left_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="15dp"
        android:padding="10dp" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/motor_arrow_selector_left" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/eye_right_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="15dp"
        android:padding="10dp" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/motor_arrow_selector_right" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/eye_up_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:padding="10dp" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/motor_arrow_selector_up" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/eye_down_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"
        android:padding="10dp" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/motor_arrow_selector_down" />
    </RelativeLayout>


    <ImageView
        android:id="@+id/disable_camera_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/disable_camera_layout"
        android:clickable="true"
        android:visibility="gone" />

</RelativeLayout>

【问题讨论】:

    标签: android android-layout camera surfaceview


    【解决方案1】:

    (我不确定这是一个简单的布局问题还是 SurfaceView 表面重叠的问题;我将其视为第二个问题。)

    SurfaceView 表面存在于单独的层上,独立于用于渲染视图层次结构的图形层。 SurfaceView 的“视图”部分只是一个透明孔,可让您通过视图层看到 Surface。

    每个表面层都有一个 Z 顺序。如果两个 Surface 试图占据同一个空间,其中一个会获胜,而获胜者并不完全是确定性的。您可以通过显式设置其中一个曲面的 Z 顺序来解决此问题。 setZOrderMediaOverlay() 调用会将层定位在默认表面位置之上,但在视图层之下。 setZOrderOnTop() 会将表面放置在视图 UI 上方。必须在创建表面之前进行调用(例如在 onCreate() 中)。

    例如,请参阅 Grafika 中的“multi-surface test”活动。

    【讨论】:

    • 当我使用每个视图的每个功能时,每个视图都覆盖第二个,我每次只看到其中一个。我需要看到他们俩
    • 您是否使用setFormat() 将表面设置为透明,将它们清除为透明颜色,并让部分透明? (再次参见 Grafika 示例。)
    • 最后我将 setZOrderMediaOverlay 添加到较小的相机视图中,现在似乎可以正常工作,感谢您的帮助!
    • 嘿@fadden 我遇到了同样的问题,你的回答很有帮助。非常感谢,但是还有一个问题。我在框架布局中动态添加表面视图,并且启用了setZOrderMediaOverlay(),但表面并未在框架布局内呈现,而是在其上方呈现。你能帮帮我吗?
    猜你喜欢
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    相关资源
    最近更新 更多