亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android切換至SurfaceView時(shí)閃屏(黑屏閃一下)以及黑屏移動(dòng)問(wèn)題的解決方法

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

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

解決:

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

2.viewpager中有surfaceview播放視頻,來(lái)回滑屏?xí)r,關(guān)于黑屏移動(dòng)問(wèn)題

解決:

surfaceview.setZorderTop(true);

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

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

相關(guān)文章

最新評(píng)論