surfaceview 使用问题

ChrisArthas 2016-05-17 12:17:02
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

这个放在onCreate 里的时候 surfaceCreated 会正常执行,

但是如果 在onCreate 里 用handler发送Delaymessage,或者 进行网络请求之后,再在handleMessage 里执行 surfaceHolder.addCallback surfaceCreated就不会被调用,有没有大神知道处理方法,万分感谢!!
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChrisArthas 2016-05-19
  • 打赏
  • 举报
回复
Android 区真的没人了么。。。。。。 终于找到解决方法,原因是surfaceviewCreated,在 surfaceview 由不可见变得可见时才会调用。所以,在onCreate里绑定完surfaceview之后,先set InVisiable,在网络请求之后,set完 URL之后,再setVisiable,surfaceCreated就可以正常调用 了 但我去官网查了下,surfaceCreated 的解释如下: void surfaceCreated (SurfaceHolder holder) This is called immediately after the surface is first created. Implementations of this should start up whatever rendering code they desire. Note that only one thread can ever draw into a Surface, so you should not draw into the Surface here if your normal rendering will be in another thread. 好像并没有提到这个。。。 最终也只找到了: The Surface will be created for you while the SurfaceView's window is visible; you should implement surfaceCreated(SurfaceHolder) and surfaceDestroyed(SurfaceHolder) to discover when the Surface is created and destroyed as the window is shown and hidden. 这样的说明
ChrisArthas 2016-05-17
  • 打赏
  • 举报
回复
引用 1 楼 birdsaction 的回复:
这个方式应该是正确的,要看你的handler代码是怎么写的。 surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 把这个都放到handler里面
handler里就是这么写的,但是surfaceCreated 并没有执行 如果在onCreate方法里,只是sendMessage,不做任何延时或者网络操作的话就可以正常执行
Birds2018 2016-05-17
  • 打赏
  • 举报
回复
这个方式应该是正确的,要看你的handler代码是怎么写的。 surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 把这个都放到handler里面

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧