[Android TV]setZOrderMediaOverlay 调整surfaceView Z-Order使用发现

最近使用了dual decode ,并且dual subtitle.

需要对四个surfaceview进行排序。

好奇怪!

addView的顺序和Z-Order的顺序相反,

即 addView(subtitleView0), addView(videoView1), addView(subtitleView2),addView(videoView3)。

然后dumpsys surfaceFlinger 发现:

Z-Order从小到大排序为:videoView3< subtitleView2< videoView1< subtitleView0。 

如果把Z-Order比喻成一座塔的话,就是说先addView进去的就在塔上面,后面addView的在塔下面,因为塔门就在一楼嘛。

然后更奇怪的来了。

我的code是这样:

先addView(subtitleView0),addView(videoView1),然后addView(subtitleView2),然后在这里Call subtitleView2.setZOrderMediaOverlay(true);

接着addView(videoView3),然后在这里Call videoView3.setZOrderMediaOverlay(true);

最后Z-Order 从小到大排序为: videoView1< subtitleView0 < videoView3 < subtitleView2;

奇怪不?其实可能不奇怪。

先来看setZOrderMediaOverlay API说明

Android.Views.SurfaceView.SetZOrderMediaOverlay Method
Control whether the surface view's surface is placed on top of another regular surface view in the window (but still behind the window itself).
Syntax
[Android.Runtime.Register("setZOrderMediaOverlay", "(Z)V", "GetSetZOrderMediaOverlay_ZHandler")]
public virtual void SetZOrderMediaOverlay (bool isMediaOverlay)
Parameters
isMediaOverlay
Documentation for this section has not yet been entered.
Remarks
Control whether the surface view's surface is placed on top of another regular surface view in the window (but still behind the window itself). 
This is typically used to place overlays on top of an underlying media surface view.
Note that this must be set before the surface view's containing window is attached to the window manager.
Calling this overrides any previous call to SurfaceView.SetZOrderOnTop(bool).

看翻译貌似是:把该sufaceview置于其余surfaceview的最上方

但这里奇怪点有三

(0)就是addView的顺序和Z-Order的顺序,可能要看source code,不知道原生的是不是被内部人改了。

(1)我在addView后面使用setZOrderMediaOverlay (true) 也生效!

(2)就是上面排序的地方,对videoView3使用setZOrderMediaOverlay(true),其竟然还是排在第二位!


所以这里在没有追踪source code的情况下猜测:setZOrderMediaOverlay (true)里面也有个排序机制,使用setZOrderMediaOverlay(true)的,只能排在之前使用过setZOrderMediaOverlay(true)的View的下方,这样才能说得过去吧。。QAQ

后面有时间看下source code理清,现在先以此记下此事!

你可能感兴趣的:(L*MM开发小结)