最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2017年01月03日 15:02:12   作者:Joanna.Yan  
本文主要介紹了Android切換至SurfaceView時閃屏(黑屏閃一下)以及黑屏移動問題的解決方法。具有一定的參考作用,下面跟著小編一起來看下吧

1.最近的項目中,有一個Activity用到Fragment+ViewPager,其中一個fragment中實(shí)現(xiàn)了視頻播放的功能,包含有SurfaceView。結(jié)果,每次打開程序第一次進(jìn)入到該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,它有自己良好的緩沖以及數(shù)據(jù)存取機(jī)制,系統(tǒng)對他有特殊處理。當(dāng)surfaceview第一次在當(dāng)前activity上添加的時候,系統(tǒng)會給WindowManager重新排布局,relayout,這樣就會黑一下,這個只會出現(xiàn)在第一次,以后再添加surfaceview時就不會黑屏了。

解決:

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

2.viewpager中有surfaceview播放視頻,來回滑屏?xí)r,關(guān)于黑屏移動問題

解決:

surfaceview.setZorderTop(true);

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

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論

师宗县| 无棣县| 五家渠市| 龙里县| 邵武市| 嵊泗县| 新野县| 碌曲县| 平顶山市| 黄浦区| 象州县| 新营市| 信阳市| 铜川市| 集安市| 天津市| 巫溪县| 卢龙县| 元氏县| 读书| 瓦房店市| 嘉黎县| 安溪县| 浦江县| 铜梁县| 西乌| 安西县| 牡丹江市| 罗城| 双鸭山市| 佛冈县| 临沧市| 惠安县| 什邡市| 宁安市| 阿城市| 塘沽区| 贡觉县| 内丘县| 绥德县| 集贤县|