简体   繁体   English

如何处理屏幕尺寸和密度的多种组合?

[英]How to handle numerous combinations of screen sizes and densities?

I'm struggling with getting the right drawables onto the right screen. 我正在努力将正确的drawables放到正确的屏幕上。 I followed the android developer instructions and created a version per drawable for ldpi through xxhdpi . 我遵循了android开发人员的说明,并通过xxhdpi为每个drawableldpi创建了一个版本。 However, physically small and large screens with the same dpi select the same drawable , where I'd like the larger screen to get a bigger one. 但是,具有相同dpi物理小屏幕和大屏幕会选择相同的drawable ,在这里我希望较大的屏幕可以获得更大的屏幕。

The layouts are pretty straight forward, so I don't think I need to create new ones with different qualifiers, so I need to come up with a good way to categorise drawables (and/or screen resolutions). 布局非常简单,因此我认为不需要使用不同的限定符来创建新的布局,因此我需要想出一种对drawables (和/或屏幕分辨率)进行分类的好方法。 I'm guessing it's done with the sw<N>dp qualifier or one of it's siblings, but how do I choose the intervals? 我猜想它是通过sw<N>dp限定词或其同级之一完成的,但是如何选择间隔? I've seen examples ( sw600dp , w820dp , etc) but no guidelines for how to determine them. 我看过示例( sw600dpw820dp等),但是没有如何确定它们的指南。 Do I need to do it by trial-and-error on different AVD configurations, and which are the best to do so with? 我需要在不同的AVD配置上通过反复试验来做到这一点,哪种方法最好?

How do I scale my drawables when I've determined which -sw<N>dp to use? 确定要使用哪个-sw<N>dp ,如何缩放可绘制对象? Do I follow the standard 3:4:6:8:12:16 or something else? 我是否遵循标准的3:4:6:8:12:16或其他标准?

Yet again, the sw<N>dp qualifiers don't seem to be for drawables , since they get scaled weirdly and blurry as a result. 再说一次, sw<N>dp限定词似乎不适合drawables ,因为它们变得怪异地缩放并且结果变得模糊。 Do I instead use layouts with the qualifiers, but how? 我应该使用带有限定符的layouts ,但是如何? I'm really at a loss here... 我真的很茫然...

However, physically small and large screens with the same dpi select the same drawable, where I'd like the larger screen to get a bigger one. 但是,具有相同dpi的物理小屏幕和大屏幕会选择相同的可绘制对象,在这里我希望较大的屏幕能够获得更大的屏幕。

Put the smaller ones in res/drawable-...dpi/ directories, for varying values of ... (eg, x ). 将较小的值放置在res/drawable-...dpi/目录中,以获取不同的...值(例如x )。 Put the larger ones in res/drawable-swNNNdp-...dpi/ , for varying values of NNN (eg, 800 ) and ... . 将较大的值放在res/drawable-swNNNdp-...dpi/ ,以更改NNN值(例如800 )和... Note that the -swNNNdp qualifier has to be in the name before the -...dpi qualifier. 请注意, -swNNNdp限定词必须位于-...dpi限定词之前。

but how do I choose the intervals? 但是如何选择间隔?

That's up to you. 随你(由你决定。 You are the one who is saying that "I'd like the larger screen to get a bigger one". 您就是在说“我希望更大的屏幕可以得到更大的屏幕”。 Only you know what you like, and only you know where the cutoff is between "larger" and not-"larger" is in your mind. 只有您知道自己喜欢什么,也只有您知道分界线在“较大”与“不”之间。 There is no universal answer for this, just as there is no universal answer for when you change the layout of a Web page to be "mobile" or not. 对此没有通用的答案,就像将网页的布局更改为“移动”或不移动时,也没有通用的答案。

Do I need to do it by trial-and-error on different AVD configurations, and which are the best to do so with? 我需要在不同的AVD配置上通过反复试验来做到这一点,哪种方法最好?

I would recommend that you try it on hardware. 我建议您在硬件上尝试一下。

If you decide that you want larger images on 7" tablets and up, -sw600dp would be a reasonable choice. If you decide that you want larger images on 10" tablets and up, -sw720dp would be a reasonable choice. 如果您决定要在7英寸以上的平板电脑上-sw600dp图像, -sw600dp是一个合理的选择。如果您决定要在10英寸以上的平板电脑上-sw720dp图像,则-sw720dp是一个合理的选择。 Beyond that, break out a ruler and measure the shortest screen width, then multiply by 160 to get dpi. 除此之外,打出直尺并测量最短的屏幕宽度,然后乘以160可获得dpi。 Google also maintains a database of many popular devices , with the dimensions in px and dpi for each. Google还维护了许多流行设备的数据库,每个设备的尺寸都以pxdpi为单位。

How do I scale my drawables when I've determined which -swdp to use? 确定要使用哪个-swdp后,如何缩放可绘制对象?

Again, that's up you. 再次,这取决于你。 If you decide that you want the images to be 50% bigger on the larger screens, create your images that are 50% bigger. 如果您决定要在大屏幕上将图像放大50%,请创建更大50%的图像。 Again, you are the one who is saying "I'd like the larger screen to get a bigger one". 再说一遍,您就是在说“我希望更大的屏幕来获得更大的屏幕”。 Only you know what you like, and only you know what "bigger" would mean to get you to something that you like. 只有您知道自己喜欢什么,也只有知道“更大”意味着将您带到您喜欢的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM