You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SurfaceView遮挡ImageView但ImageView仍可点击的布局层级问题求助

SurfaceView遮挡ImageView但ImageView仍可点击的布局层级问题求助

大家好,我最近在做视频通话界面开发,遇到了一个SurfaceView与ImageView的层级显示问题,想请教下各位开发者:

我用RelativeLayout作为根布局,里面放置了两个自定义的RoundCornerSurfaceView(分别承载本地摄像头画面和远程流画面),还有一个用于切换窗口大小的ImageView。为了确保小窗口SurfaceView不被大窗口完全遮挡,我使用了setZOrderMediaOverlay方法,现在小窗口显示正常,但ImageView却被SurfaceView挡住看不见了——不过奇怪的是,点击ImageView所在的位置,依然能触发窗口切换逻辑,说明触摸事件可以正常传递,只是视觉上被遮挡了。

我的布局代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:clipChildren="false"
    android:clipToPadding="false">

    <com.meituan.ai.multiinteraction.demo.view.RoundCornerSurfaceView
        android:id="@+id/local_video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible" />

    <com.meituan.ai.multiinteraction.demo.view.RoundCornerSurfaceView
        android:id="@+id/remote_video_view"
        android:layout_width="124dp"
        android:layout_height="222dp"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="12dp"
        android:layout_marginBottom="180dp" />

    <ImageView
        android:id="@+id/iv_expand"
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:scaleType="centerCrop"
        android:layout_marginStart="100dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="370dp"
        android:src="@drawable/icon_expand" />
</RelativeLayout>

窗口切换的逻辑代码

private fun swapVideoViews() {
    if (remoteViceIsExpand) {
        expandLocalVideo()
    } else {
        expandRemoteVideo()
    }
    remoteViceIsExpand = !remoteViceIsExpand
}

private fun expandRemoteVideo() {
    ... // 此处为设置宽高的业务代码
    serverVideoView?.translationZ = 0f
    localVideoView?.translationZ = 100f
    serverVideoView?.setZOrderOnTop(false)
    localVideoView?.setZOrderOnTop(true)
    localVideoView?.setZOrderMediaOverlay(true)
    ivExpand?.translationZ = 200f
}

private fun expandLocalVideo() {
    ... // 此处为设置宽高的业务代码
    localVideoView?.translationZ = 0f
    serverVideoView?.translationZ = 100f
    localVideoView?.setZOrderOnTop(false)
    serverVideoView?.setZOrderOnTop(true)
    serverVideoView?.setZOrderMediaOverlay(true)
    ivExpand?.translationZ = 200f
}

我原本以为给ImageView设置更高的translationZ就能让它显示在最上层,结果视觉上还是被SurfaceView遮挡了。有没有朋友遇到过类似的问题?怎么才能让ImageView正常显示在SurfaceView的上方呢?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 09:13:04