国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android切換至SurfaceView時閃屏(黑屏閃一下)以及黑屏移動問題的解決方法

2019-12-12 04:08:53
字體:
來源:轉載
供稿:網友

1.最近的項目中,有一個Activity用到Fragment+ViewPager,其中一個fragment中實現了視頻播放的功能,包含有SurfaceView。結果,每次打開程序第一次進入到該Activity時都會閃屏黑一下。原因就出在SurfaceView。

詳解:

  I think I found the reason for the black flash. In my case I'm using a SurfaceView inside a Fragment and dynamically adding this fragment to the activity after some action. The moment when I add the fragment to the activity, the screen flashes black. I checked out grepcode for the SurfaceView source and here's what I found: when the surface view appears in the window the very fist time, it requests the window's parameters changing by calling a private IWindowSession.relayout(..) method. This method “gives” you a new frame, window, and window surface. I think the screen blinks right at that moment.
   The solution is pretty simple: if your window already has appropriate parameters it will not refresh all the window's stuff and the screen will not blink. The simplest solution is to add a 0px height plain SurfaceView to the first layout of your activity. This will recreate the window before the activity is shown on the screen, and when you set your second layout it will just continue using the window with the current parameters. I hope this helps.

原因:

SurfaceView因為不同于一般的view,它有自己良好的緩沖以及數據存取機制,系統對他有特殊處理。當surfaceview第一次在當前activity上添加的時候,系統會給WindowManager重新排布局,relayout,這樣就會黑一下,這個只會出現在第一次,以后再添加surfaceview時就不會黑屏了。

解決:

可以在沒有進入surfaceview的界面(比如很多程序一進去就有個Loading界面)的時候,在其它界面的layout.xml文件中添加一個SurfaceView,寬和高都弄成0dp,這樣對布局沒影響,而且這個東西使得surfaceview第一次出現了,那么也就是說,下一次我們真正用到SurfaceView的時候就不會閃屏了。

2.viewpager中有surfaceview播放視頻,來回滑屏時,關于黑屏移動問題

解決:

surfaceview.setZorderTop(true);

surfaceview.getHolder().setFormat(SurfaceView.TRANSPARENT);

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌拉特前旗| 上思县| 揭西县| 白沙| 齐齐哈尔市| 新野县| 兴城市| 张家口市| 涿鹿县| 镇江市| 浪卡子县| 汝阳县| 九龙坡区| 且末县| 青铜峡市| 中阳县| 徐州市| 胶南市| 新竹市| 赤水市| 桂东县| 东乌珠穆沁旗| 上思县| 曲沃县| 工布江达县| 日照市| 容城县| 常德市| 正宁县| 凤阳县| 四川省| 德江县| 遂宁市| 大邑县| 上饶县| 张家口市| 余干县| 克拉玛依市| 离岛区| 潮州市| 盖州市|