如何混合nodpi和普通/中/小/大资源

发布于 2024-09-24 10:42:03 字数 329 浏览 3 评论 0原文

我试图在我的应用程序中混合 nodpi 资源和非 nodpi 资源,但它不起作用。当我仅使用 nodpi 时,报告的屏幕尺寸为 480x800(例如),并且所有位图均正确绘制。但是,当我在可绘制法线中放置单个位图时,分辨率会降低,这不是我想要的行为。

我正在寻找的是将不会根据屏幕规格(nodpi 位图)进行缩放的资源与我希望 android 负责选择合适尺寸的其他位图混合在一起。

如果这没有意义,让我用一个例子来解释它:我希望字体/按钮/其他 UI 元素能够缩放,但游戏的背景不应该大于游戏的尺寸屏幕。最后一部分必须是 nodpi (在较小尺寸的屏幕上有更多的滚动)。

我怎样才能做到这一点?

I am trying to mix nodpi resources and non-nodpi resources in my application, but it just doesn't work. When I work with nodpi only, the screen size reported is 480x800 (for example) and all the bitmaps are drawn properly. But when I drop a single bitmap in drawable-normal, the resolution is lowered and that is not the behaviour I want.

What I am looking for is to mix assets that are not to be scaled according depending of the screen specs (the nodpi bitmaps) with other bitmaps that I would like android to take charge of choosing the proper size.

In case that doesn't make sense, let me explain it with an example: I want the fonts/buttons/other-UI-elements to scale, but not the background of the game that is supposed to take larger than the size of the screen. The last part must be nodpi (there is simply more scrolling on the smaller size screen).

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫性小仙女 2024-10-01 10:42:03

让我看看这是否有道理。如果你在 nodpi 文件夹中有一个资源,那么你不应该在另一个文件夹中有相同名称的资源,比如drawable-normal。这是因为正如你所说,nodpi 意味着这些图像不应该缩放,现在如果你将它们放在可绘制的普通 android 中,它将自动尝试缩放它。希望这是有道理的。

Let me see if this makes sense. If you have an asset in nodpi folder, you shouldnt have same name asset in another folder, like say drawable-normal. This is because as you said, nodpi means those images shouldnt be scaled, now if you have them in drawable-normal android will automatically try to scale it.Hope this makes sense.

皇甫轩 2024-10-01 10:42:03

好的,我找到了一个解决方案:在加载不需要缩放的位图时,即使它们位于 nodpi 文件夹中,我也指定选项 inScaled = false 。这样,它们就不会以很大的比例显示。

我当然不了解有关资源系统的所有内容,因为它似乎没有多大意义。但它有效。

Ok, I found a solution: when loading the bitmaps that I don't to be scaled, even if they are in the nodpi folder, I specify the option inScaled = false. That way, they are not displayed in very large scale.

I am certainly not understanding everything about the resource systems, because it doesn't seem to make that much sense. But it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文