简体   繁体   English

不同屏幕尺寸的图像。

[英]Images for Different Screen sizes.?

I read the article http://developer.android.com/guide/practices/screens_support.html 我读了文章http://developer.android.com/guide/practices/screens_support.html

I'm not quite clear on this: do I have to make different XML layouts to support different screen sizes? 我对此不太清楚:是否必须制作不同的XML布局以支持不同的屏幕尺寸?

Maybe there is a simple example that explains this in a way that is easier to understand? 也许有一个简单的示例以更容易理解的方式解释了这一点?

No, the whole point of density is that one layout should work on all phones and devices. 不,密度的全部要点是,一种布局应适用于所有电话和设备。 There's a good example of how to lay out buttons in a layout here . 还有如何在布局布局按钮一个很好的例子在这里

Note on that link how one of the views has android:layout_marginTop="94dp" As long as you use dp, your layout should be fine for all devices. 请注意该链接上的视图之一如何具有android:layout_marginTop="94dp"只要您使用dp,您的布局就应该适合所有设备。

Another way to put it: you don't have to worry about screen sizes as long as: a) You always measure distance in dp, not pixels b) You always measure font size in sp, not pixels c) For each image, you put different sizes of the image in the different resource folders (hdpi, xdhpi, etc) 换句话说:您不必担心屏幕尺寸,只要:a)您始终以dp为单位测量距离,而不是像素b)您始终以sp为单位而不是像素来测量字体大小c)对于每个图像,您都可以将不同大小的图像放入不同的资源文件夹(hdpi,xdhpi等)中

If you follow those rules, one layout should look very similar on all sizes of screens. 如果遵循这些规则,则在所有尺寸的屏幕上,一种布局都应该看起来非常相似。

No, you do not have to provide a layout for every size screen. 不,您不必为每个尺寸的屏幕都提供布局。 You only have to have one layout for a screen. 屏幕只需要有一种布局。 But by leveraging he resource system, you can provide alternate versions of your layout where it is appropriate. 但是,通过利用资源系统,您可以在适当的地方提供布局的替代版本。 For example, maybe you want one layout for phones and a second layout for tablets. 例如,也许您想要一种布局用于手机,另一种布局用于平板电脑。

Maybe not layout xmls but dimen xmls that should be repeated. 也许不是布局xml,而是应该重复的dimen xml。

Sometimes,use dp can be help if you do not have to accurate to little pixels. 有时,如果您不必精确到小像素,使用dp可能会有所帮助。

I'm not quite clear on this: do I have to make different XML layouts to support different screen sizes? 我对此不太清楚:是否必须制作不同的XML布局以支持不同的屏幕尺寸?

No. Make relative statements, such as android:layout_width="match_parent" . 否。做出相对的陈述,例如android:layout_width="match_parent" Use 9-patches to define stretchable images. 使用9色块定义可拉伸图像。 File density and screen size dependent resources in the appropriate directory drawable, such as drawable-xhdpi . 适当的目录drawable中依赖文件密度和屏幕尺寸的资源,例如drawable-xhdpi This will mean supplying the same image resource multiple times at different resolutions. 这将意味着以不同的分辨率多次提供相同的图像资源。 ldpi is 33.33% of xhdpi , mpdi is 50%, and hdpi is 75%. ldpi是33.33% xhdpimpdi是50%,和hdpi是75%。 xhpi is comparable to iPhone Retina: If someone gives you iOS Retina image assets, you can scale each of these down accordingly for Android. xhpi可与iPhone Retina媲美:如果有人为您提供iOS Retina图像资产,则可以针对Android将这些资产相应缩小。

A good occasion where you will have to make different XML layouts is if you're trying to remain backwards compatible. 如果要保持向后兼容,则必须进行不同的XML布局的一个好时机。 For example, android:layout_marginStart is only available from API 17 when Google started worrying about right-to-left text. 例如,仅当Google开始担心从右到左的文本时,才可以从API 17中使用android:layout_marginStart This will fail silently on older devices, where instead you have to provide the same layout in layout-v10 say with android:layout_marginStart replaced by android:layout_marginLeft . 这将在旧设备上无声地失败,取而代之的是,您必须在layout-v10提供相同的布局,用android:layout_marginStart替换为android:layout_marginLeft

Last, think of your Android user interface as being a webpage. 最后,将您的Android用户界面视为网页。 The only safe assumption you can make is that you have to fill space, don't presume how much space you have to fill. 您可以做的唯一安全的假设是必须填充空间,而不要假设必须填充多少空间。

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

相关问题 平板电脑的设计应用程序以支持不同的屏幕尺寸。 - Designing application for tablets to support different screen sizes. 将小部件定位在堆栈中,在模拟器中或根据不同的屏幕尺寸更改 position。 Flutter - Positioned widget in a Stack changing position in emulator or according to different screen sizes. Flutter 应用适合多种屏幕尺寸。 但我所知道的 - App fits multiple screen sizes. but one that I know of 了解支持与图像有关的不同屏幕尺寸 - Understanding supporting different screen sizes relating to Images Android图片可在不同屏幕尺寸下正确缩放 - Android images to scale properly in different screen sizes 如何制作不同屏幕尺寸的图像? - How to make images for different screen sizes? 如何为不同的屏幕尺寸android使用不同的图像? - How to use different images for different screen sizes android? 在某些较小的屏幕尺寸下,Malayalam文本在TextView中不可见。 (英文文本没有问题) - Malayalam text goes out of view in TextView, in some smaller screen sizes. (No issues with English text) 在Android上重复使用不同屏幕尺寸和密度的可绘制图像 - Reuse drawable images for different screen sizes and densities on Android 使用毕加索从服务器加载不同屏幕尺寸的图像吗? - Load images for different screen sizes from the server using picasso?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM