1、SurfaceView遮擋其他控件的項(xiàng)目背景:
由于要實(shí)現(xiàn)視頻、地圖大小窗口切換功能,所以在布局里同時(shí)使用了videoView和SurfaceView,textview、imageview、自定義控件各種按鈕控件。在這種背景下,問題出現(xiàn)了,如果用相關(guān)開發(fā)基礎(chǔ)的同學(xué)應(yīng)該知道,當(dāng)MapView和SurfaceView同時(shí)在一個(gè)布局里面,如果想讓SurfaveView顯示圖片或者視頻必須要調(diào)用SurfaceView.setZOrderOnTop(true),也就是說必須把SurfaceView置于Activity顯示窗口的最頂層才能正常顯示,然后調(diào)用了SurfaceView.setZOrderOnTop(true)又導(dǎo)致了其他控件比如播放、快進(jìn)等按鈕被遮擋。網(wǎng)上有很多解決方案,比如解決SurfaceView設(shè)置透明造成遮蓋其他組件的替代方案,對于視頻播放的頁面都不夠完美,因?yàn)樗侵苯釉赟urfaceView上面繪制相關(guān)的控件,試想一下如果在SurfaceView的某些區(qū)域繪制了一些按鈕,勢必會擋住一部分視頻畫面,這樣對于用戶來說是很難接受的。
2、從SurfaceView源碼中尋找解決方案:
由于在網(wǎng)上找的解決方案都不能滿足要求,沒辦法有折回來查看了下SurfaceView的源碼,在查看源碼的時(shí)候看到這個(gè)方法setZOrderMediaOverlay(boolean isMediaOverlay),下來我們來看看源碼中對這個(gè)方法的描述:
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 {@link #setZOrderOnTop}.
大概的意思就是說控制窗口中表面的視圖層是否放置在常規(guī)視圖層的頂部。
最終,我在調(diào)用setZOrderOnTop(true)之后調(diào)用了setZOrderMediaOverlay(true),OK,遮擋問題完美解決!
原文地址:http://blog.csdn.net/u013068887/article/details/72729174?locationNum=14&fps=1