gpt4 book ai didi

Android-调整图像大小以匹配屏幕高度

转载 作者:行者123 更新时间:2023-11-29 22:06:13 25 4
gpt4 key购买 nike

在我的应用程序中,对于相对布局的背景,我有一个非常大的网状墙纸(比任何手机/桌面屏幕都大)。所以,我想知道不是让 android 调整它的大小并让它看起来很糟糕,我可以自己调整它的大小。我想要做的是调整图像的大小(垂直和水平方向,以保持它看起来不错)直到图像和屏幕的高度匹配。

谢谢,感谢所有帮助- Lijap

最佳答案

Google 投入了大量精力来解决这个问题。

基本上,您应该为每个目标尺寸/布局创建不同的尺寸。

这在 Google Dev Guide documents for Supporting Multiple Screens 中有广泛的解释(比我能给出的要好得多)

从那个页面:

Screen size

Actual physical size, measured as the screen's diagonal. For simplicity, Android groups all actual screen sizes into four generalized sizes: small, normal, large, and extra large.

Screen density

The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch).

For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen. For simplicity, Android groups all actual screen densities into four generalized densities: low, medium, high, and extra high.

Orientation

The orientation of the screen from the user's point of view. This is either landscape or portrait, meaning that the screen's aspect ratio is either wide or tall, respectively. Be aware that not only do different devices operate in different orientations by default, but the orientation can change at runtime when the user rotates the device.

Resolution

The total number of physical pixels on a screen. When adding support for multiple screens, applications do not work directly with resolution; applications should be concerned only with screen size and density, as specified by the generalized size and density groups.

Density-independent pixel (dp)

A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way. The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

这样,您的用户将看到与其设备大小相匹配的位图。

如果您需要帮助理解文档,或者如果这不能正确回答您的问题,请告诉我。

关于Android-调整图像大小以匹配屏幕高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10760940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com