本文介绍了为什么在使用 GONE 设置可见性并继续使用 VISIBLE 时调用 SurfaceCreated 和 surfaceDestroyed 多次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这段代码会导致surfaceCreated和surfaceDestroyed被多次调用:

i found that this codes will cause surfaceCreated and surfaceDestroyed to be called several times:

mSurfaceView.setVisibility(View.GONE);
mSurfaceView.setVisibility(View.VISIBLE);   

谁能告诉我为什么surfaceCreated和surfaceDestroyed不能只被调用一次?

could anybody tell me why surfaceCreated and surfaceDestroyed doesn't to be called only once ?

推荐答案

如果你实现了 SurfaceHolder.Callback 并在 surfaceDestroyedsurfaceCreated 的每一个里面放了一个记录器, surfaceChanged 方法,您将看到这两行将生成以下输出:

If you implement SurfaceHolder.Callback and put a logger inside each of surfaceDestroyed, surfaceCreated, surfaceChanged methods, you will see that those two lines will generate the following output:

04-01 12:50:54.688: INFO/app(4842): SurfaceView destroyed!
04-01 12:50:54.688: INFO/app(4842): SurfaceView created!
04-01 12:50:54.718: INFO/app(4842): SurfaceView changed!

在调用 setVisibility 之前和之后使用两个断点,只需确保不计算其他日志.

Using two breakpoints before and after the calls to setVisibility, just make sure you don't count other logs.

这篇关于为什么在使用 GONE 设置可见性并继续使用 VISIBLE 时调用 SurfaceCreated 和 surfaceDestroyed 多次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 05:46