解決SurfaceView調用setZOrderOnTop(true)遮擋其他控制項的問題

來源:互聯網
上載者:User

標籤:

  1. SurfaceView遮擋其他控制項的項目背景:

    最近在做播放器項目,由於底層實現是用Surface和OpenGL切換渲染,所以在布局裡面同時使用了GLSurfaceView和SurfaceView,同時播放控制按鈕是自訂的,也沒有使用Android自己提供的MediaCtroller控制項。在這種背景下,問題出現了,如果有相關開發基礎的同學應該知道,當SurfaceView和GLSurfaceView同時在一個布局裡面,如果想讓SurfaveView顯示圖片或者視頻必須要調用SurfaceView.setZOrderOnTop(true),也就是說必須把SurfaceView置於Activity顯示視窗的最頂層才能正常顯示,然後調用了SurfaceView.setZOrderOnTop(true)又導致了其他控制項比如播放、快進等按鈕被遮擋。網上有很多解決方案,比如解決SurfaceView設定透明造成遮蓋其他組件的替代方案,對於視頻播放的頁面都不夠完美,因為它是直接在SurfaceView上面繪製相關的控制項,試想一下如果在SurfaceView的某些地區繪製了一些按鈕,勢必會擋住一部分視頻畫面,這樣對於使用者來說是很難接受的。

  2. 從SurfaceView源碼中尋找解決方案:

    由於在網上找的解決方案都不能滿足要求,沒辦法有折回來查看了下SurfaceView的源碼,在查看源碼的時候看到這個方法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.

 

  Calling this overrides any previous call to {@link #setZOrderOnTop}.

  大概的意思就是說控制視窗中表面的視圖層是否放置在常規視圖層的頂部。

 

  最終,我在調用setZOrderOnTop(true)之後調用了setZOrderMediaOverlay(true),OK,遮擋問題完美解決!

  

本文出自 “西城天部” 部落格,請務必保留此出處http://marller.blog.51cto.com/8699646/1762028

解決SurfaceView調用setZOrderOnTop(true)遮擋其他控制項的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.