简体   繁体   中英

SurfaceView blinks the screen for first time - Android

I want to use SurfaceView for animation to show the live camera preview. It is working fine. But when it loads for first time it flickering for first time.

This is common issue with android surface view.

Window was destroyed then re-created when the SurfaceView was adding, and the Window's pixel format was changed mean while, that guided me to the answer, the pixel format of the SurfaceView and the Activity was different so Window Manager forced the re-created.

To resolve it, just added one line in onCreate() to set pixel format, as below:

getWindow().setFormat(PixelFormat.TRANSLUCENT);

Adding a 0px height blank surfaceView to the first layout of the activity might solve the issue. It is a crazy solution, but it solved the issue for me.

You could also check the following query which has a full explanation of answer. " SurfaceView flashes black on load "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM