有一個這樣的需求,下面有2個tab進行切換,第一個是錄像界面(暫定爲界面A),第二個是拍照界面(暫定爲界面B),我第一個想到的就是用SurfaceView控件來實現,在佈局文件裏面它的屬性很簡單的。然後就想着錄像界面就顯示錄像預覽畫面,拍照界面就顯示拍照預覽畫面,但是當我切換的時候問題就來了。第一次打開應用是進入界面A,當我切換到界面B時,發現界面A的預覽畫面還顯示在界面B上,這樣就遮擋了界面B的SurfaceView,這樣肯定是不行的,然後我就去查看了SurfaceView的開發文檔。
public void setZOrderMediaOverlay (boolean isMediaOverlay)
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.