【问题标题】:android add view over surfaceViewandroid在surfaceView上添加视图
【发布时间】:2017-08-05 08:09:12
【问题描述】:

我只想进行视频通话布局,但我遇到了这个问题 我想在 SurfaceView 上添加一些 imageView 和按钮,用于切换摄像头、静音、结束通话和一些信息,这是我的 xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
    >


<org.webrtc.SurfaceViewRenderer
    android:id="@+id/preview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">



<LinearLayout
    android:id="@+id/rind"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
      <!-- here my ImageView and button -->

     </LinearLayout>



</RelativeLayout>

SurfaceViewRenderer 扩展surfaceView

现在,当我运行此程序时,我在 surfaceView 中看不到我的相机,我为 SurfaceViewRenderer 添加了红色背景,它出现时没有我的相机显示但我看不到我的观点(静音,结束通话......)

我也试试

   mySurfaceView.setZOrderMediaOverlay(true);

   mySurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);

没有影响

我只想做这样的布局

在我使用surfaceView 之前,我尝试过glsurfaceview,但它是一样的,我读到我在 glsurfaceview 中做不到(在 glsurfaceview 上添加视图)

【问题讨论】:

    标签: android surfaceview


    【解决方案1】:

    试试这个希望对你有帮助

    并为顶部服务设置 setZOrderMediaOverlay(true) 和 setZOrderMediaOverlay(false) 为下一个服务

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"
      tools:context="com.discuss.app.call.CallScreen" android:id="@+id/backgroundImage" android:background="@color/black" android:windowSoftInputMode="stateHidden">
    
    
      <LinearLayout android:layout_width="wrap_content" android:id="@+id/remoteVideoContainer" android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" android:background="@color/black">
        <org.webrtc.SurfaceViewRenderer android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/remoteVideoViewSurface" android:visibility="gone" android:backgroundTint="@color/darkBackgroundColor" />
      </LinearLayout>
    
      <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintEnd_toStartOf="parent" app:layout_constraintStart_toEndOf="parent" app:layout_constraintBottom_toTopOf="parent" app:layout_constraintTop_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.284" app:layout_constraintVertical_bias="0.492" android:id="@+id/localVideoContainer" android:elevation="7dp" android:background="@color/black">
        <org.webrtc.SurfaceViewRenderer android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/localVideoViewSurface" android:visibility="gone" />
      </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

    【讨论】:

      【解决方案2】:

      试试这个希望对你有帮助:

      <?xml version="1.0" encoding="utf-8"?>
      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      
      <FrameLayout
          android:clipChildren="false"
          android:id="@+id/main_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
      <!--local view-->
      <com.example.gwl.apprtc.PercentFrameLayout
          android:id="@+id/local_video_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
      <org.webrtc.SurfaceViewRenderer
              android:id="@+id/local_video_view"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"/>
      <!--remote View -->
      </com.example.gwl.apprtc.PercentFrameLayout>
      <com.example.gwl.apprtc.PercentFrameLayout
          android:id="@+id/remote_video_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
      <org.webrtc.SurfaceViewRenderer
              android:id="@+id/remote_video_view"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"/>
      
      </com.example.gwl.apprtc.PercentFrameLayout>
      <!---->
      </FrameLayout>
      <FrameLayout
          android:id="@+id/buttons_call_container"
          android:orientation="horizontal"
          android:layout_marginBottom="@dimen/marginBottom_32dp"
          android:layout_gravity="bottom|center"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content">
      
      <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal">
      
      <ImageButton
                  android:id="@+id/button_call_disconnect"
                  android:background="@drawable/disconnect"
                  android:contentDescription="@string/disconnect_call"
                  android:layout_width="@dimen/layoutWidth_48dp"
                  android:layout_height="@dimen/layoutHeight_48dp"/>
      
      <ImageButton
                  android:id="@+id/button_call_toggle_mic"
                  android:background="@android:drawable/ic_btn_speak_now"
                  android:contentDescription="@string/toggle_mic"
                  android:layout_marginRight="@dimen/marginRight_10dp"
                  android:layout_width="@dimen/layoutWidth_48dp"
                  android:layout_height="@dimen/layoutHeight_48dp"/>
      
      <ImageButton
                  android:id="@+id/button_call_switch_camera"
                  android:background="@android:drawable/ic_menu_camera"
                  android:layout_marginEnd="8dp"
                  android:layout_width="48dp"
                  android:layout_height="48dp"/>
      
      
      </LinearLayout>
      
      </FrameLayout>
      
      </FrameLayout>
      

      【讨论】:

        猜你喜欢
        • 2014-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-31
        • 2016-01-13
        • 2013-05-19
        • 2012-06-11
        • 1970-01-01
        相关资源
        最近更新 更多