Android 上的 java 类 Dimension
Android 类 java.awt.Dimension
的等效形式是什么?
What is the equivalent form of class java.awt.Dimension
for android?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以选择以下选项之一:
android.util.Size
(自 API 21 起)。它有getWidth()
和getHeight()
,但请注意它是不可变的,这意味着一旦创建就无法修改它(只能创建新的、更新的实例)。android.graphics.Rect
。它有getWidth()
和getHeight()
但它们基于内部left
、top
、right
、bottom
并且可能看起来因所有额外的变量和实用方法而显得臃肿。android.graphics.Point
这是一个普通的容器,但是名字不对,它的主要成员叫做x
和y
这对于调整尺寸来说并不理想。 但是,这似乎是从 Android 框架本身获取显示宽度和高度时要使用/滥用的类,如下所示:You can choose one of these options:
android.util.Size
(since API 21). It hasgetWidth()
andgetHeight()
, but note it's immutable, meaning that once created you can't modify it (only create new, updated instances).android.graphics.Rect
. It hasgetWidth()
andgetHeight()
but they're based on internalleft
,top
,right
,bottom
and may seem bloated with all its extra variables and utility methods.android.graphics.Point
which is a plain container, but the name is not right and it's main members are calledx
andy
which isn't ideal for sizing. However, this seems to be the class to use/abuse when getting display width and height from the Android framework itself as seen here:您可以使用
Pair
这是 Android 的通用元组类。 (不过,您需要将getWidth()
和getHeight()
替换为first
和second
。) Android 团队似乎在 Android API 的其他地方使用临时类来实现此目的,例如相机大小
。You could use
Pair<Integer, Integer>
which is Android's generic tuple class. (You would need to replacegetWidth()
andgetHeight()
withfirst
andsecond
, though.) In other places of the Android API the Android team seems to use ad-hoc classes for this purpose, for instanceCamera.Size
.为什么你需要滥用其他类而不是实现一些非常简单的东西,例如:
Why do you need to abuse other classes instead of implementing something extremely simple like: