获取SurfaceView尺寸
我想我可能会问一个虚拟问题,但我对 Android 编程还是个新手,而且我无法(尽管我尽了所有努力)在 Google 上找到答案。
问题是,我正在尝试开发一个带有 2D 图形的小游戏。我希望我的“游戏板”位于屏幕上的特定位置,以便我可以在框的上方和下方显示游戏中的信息。但由于开始出现很多 Android 手机,我正在考虑获取“动态”值,以便我可以调整字体大小以适应每个设备。
我的游戏不是全屏(但也有可能,没什么大不了的),而是在没有标题栏的窗口中。
我使用默认 SurfaceView
类的扩展,实现 SurfaceHolder.Callback
。我尝试编写以下方法:
public void getViewSize()
{
VIEW_WIDTH = this.getWidth();
VIEW_HEIGHT = this.getHeight();
}
但返回的值为零。
有人有想法吗(即使这意味着改变显示策略)? 多谢。
I think I might be about to ask a dummy question, but I'm still new with Android programming, and I couldn't (despite all my efforts) find my answer on Google.
The thing is, I'm trying to develop a little game, with 2D Graphics. I want my "gaming board" to be at a specific position on my screen, so that I can display in-game informations above and below the box. But since there is beginning to be a lot of Android phones out there, I was thinking about getting "dynamic" values so that I can adapt my font size to every device.
My game is not in full screen (but it could be, it's no big deal), but in a window with no title bar.
I'm using an extension of the default SurfaceView
class, implementing SurfaceHolder.Callback
. I tried writing the following method :
public void getViewSize()
{
VIEW_WIDTH = this.getWidth();
VIEW_HEIGHT = this.getHeight();
}
but the values returned are zeroes.
Anyone got an idea (even if it means changing display strategy) ?
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做:
You can do this: