表面观的z-index变化OnResume /将OnPause的Andr​​oid之后表面、index、OnResume、oid

2023-09-06 18:13:56 作者:毁我现在废你未来

我有一个关于在Android上的观点的z-index一个疑问。我有一个GLSurfaceView的活动,另一个SurfaceView的视频播放。我读过多面的观点是不会长久被放置在相同的布局在互联网上,但这些职位都是慈祥的老人​​,我不知道这是否仍然是正确的。

I have a doubt regarding z-index on Android views. I have an activity with a GLSurfaceView and another SurfaceView for video playback. I've read on the internet that multiple surface views are not made to be placed on the same layout, but these posts are kind of old and I don't know if this is still true.

不管怎样,我有问题的意见的顺序。我想VideoView是GLSurfaceView后面。它的工作原理当应用程序启动,因为我调用该方法setZOrderOnTop(假)的VideoView时,它的构造。

Anyway, i have problem with the order of the views. I want the VideoView to be behind the GLSurfaceView. It works when the apps starts because I call the method setZOrderOnTop(false) on the VideoView when it's constructed.

public class LBVideoView extends SurfaceView implements OnPreparedListener, OnCompletionListener, SurfaceHolder.Callback {

private Context m_context;

public LBVideoView(Context context) {
    super(context);
    m_context = context;

    init();
}

private void init()
{
    this.getHolder().addCallback(this);
    this.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setZOrderOnTop(false); //CODE TO SET VIDEO VIEW TO BACK
}
}

当应用程序被切换到后台,后来被恢复的问题发生。该VideoView来前,无论我做什么,运行的Andr​​oid 4.1.2的设备上。在我的Nexus 5,运行Android 4.4系统的它永远不会发生。是这样的改变在最新的Andr​​oid版本?我需要保持与旧版本兼容...

The problem happens when the app goes to background and is resumed later. The VideoView comes to front no matter what I do on a device that runs Android 4.1.2. On my Nexus 5 that runs Android 4.4 it never happens. Was this changed on the newest Android versions? I need to keep compatibility with older versions...

如果我删除所有的意见,然后再添加它的工作原理,但是这并不能帮助我,因为它破坏了影片的表面来看,我不希望这样的事情发生。

If I remove all the views and add again it works, but this doesn't help me because it destroys the surface view of the video and I don't want that to happen.

有谁知道如何保持表面认为是GLSurfaceView后面的后面,甚至在简历?

Does anyone know how to keep the surface view that is behind the GLSurfaceView behind, even after resume?

推荐答案

首先, #setZOrderOnTop(布尔),不直接控制相对于表面的Z排序对方(我不知道它在全国各地的任何控制权。)这是记录为控制z顺序面相对向应用程序的窗口。

First, #setZOrderOnTop(boolean), does not directly control the z-ordering of surfaces relative to each other (I don't know if it has any control over that at all.) It's documented as controlling the z-order of the surface relative to the "window" of the app.

glSurfaceView.setZOrderMediaOverlay(真)可能是你想要的东西。这将保持glSurfaceView上LBVideoView的顶部。 AFAIK这是控制Z顺序的两个表面相对于彼此的唯一方式。

glSurfaceView.setZOrderMediaOverlay(true) is probably what you want. That will keep the glSurfaceView on top of the LBVideoView. AFAIK this is the only way to control the z-order of two surfaces relative to each other.