通过Kivy正确使用指标(因此GUI可以在所有设备上很好地扩展) [英] Proper usage of metrics with Kivy(So GUI scales well across devices)

查看:85
本文介绍了通过Kivy正确使用指标(因此GUI可以在所有设备上很好地扩展)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的游戏在不同设备上的外观/缩放比例更好.我试图将dpsp指标尽可能多地引入我的应用程序,但是在这种情况下,我正在重构游戏以将这些指标用于布局和小部件大小调整.

I am trying to get my game to look/scale well across different devices. I am attempting to introduce the dp and sp metrics into my apps as much as possible, but in this case I am refactoring a game to use these metrics for layout and widget sizing.

之前,我使用size_hint调整了我的布局的大小,以使所有内容都相对于其父项获得大小(该应用程序本身未指定大小,窗口也未指定大小,但是根窗口小部件/布局具有),我现在面临的是用dp值替换该系统,并且无法弄清楚它们应该是什么.

Where before, my layouts were sized using size_hint in order to have everything get it's size relative to it's parent(the app itself is not given a size, nor is the window, but the root widget/layout has size_hint=(1, 1)), I am now faced with replacing this system with dp values, and can't figure out what they should be.

我在想,如果仅使用dp调整 root小部件 App 本身或 Window 的大小,那么我可以继续使用size_hint ing,因为这样会产生a流的效果,并且可以正确地从上到下按比例缩放所有内容.为此,似乎获得设备屏幕的分辨率或密度将是一个很大的帮助(因此我可以使用它来调整每个设备的根窗口小部件/应用程序/窗口的大小). Kivy有可能吗?这会工作吗?有没有更好的办法?你会怎么做?谢谢

I am thinking, that if I just size the root widget, App itself, or Window with dp, then I could continue to use size_hinting, as this would have a trickle down effect and scale everything correctly from the top on down, so to speak. And for this, It seemed like getting the resolution or density of a devices screen would be a great help(so I could use it to size my root widget/App/Window, per device). Is that possible with Kivy? Will this work? Is there a better way? What would you do? Thanks

推荐答案

单独使用size_hint已经可以保证一定程度的规模独立性,因为(如您所述)所有大小都是相对的.

Using size_hint alone already guarantees a degree of scale independence, as (as you note) all the sizes will be relative.

Kivy内部检查设备的一些与分辨率相关的值,这基本上是dp的要点;例如,在任何设备上,例如dp(10)之类的东西在屏幕上的实际大小都应为 actual (实际)大小.厘米.实际上,这并不是很正确,如果我认为没有其他设备不能报告准确的结果,但是除非这非常重要,否则它将已经开始确保在任何地方看起来都差不多.

Kivy internally checks some resolution related values of the device, and this is basically the point of dp; something like dp(10) for instance should be the same actual size on any device, in terms of real size on the screen in e.g. centimetres. This won't actually be quite right, if nothing else I think devices don't report precisely right results, but unless this is very important it will already take care of making things mostly look the same anywhere.

我不确定您对设置应用程序大小的含义-在Android的窗口管理器中,一个应用程序会填满整个屏幕(至少在大多数情况下).

I'm not sure what you mean about setting the App size - in Android's window manager an App just fills the screen (at least in most cases).

这篇关于通过Kivy正确使用指标(因此GUI可以在所有设备上很好地扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆