简体   繁体   English

不同的屏幕尺寸

[英]Different screen sizes

I have looked through all of the android docs and many stack overflow questions, and I have a question on supporting multiple screen sizes. 我浏览了所有的android文档和许多堆栈溢出问题,并且对支持多种屏幕尺寸有疑问。 If I have some drawables, I know I need to put them in folders like these: 如果我有一些可绘制对象,我知道我需要将它们放在以下文件夹中:

在此处输入图片说明

But does android make these folders for me? 但是android是否为我制作了这些文件夹? When I try copy and pasting my images into the drawable folder, I get something like this: 当我尝试将图像复制并将其粘贴到drawable文件夹中时,会得到以下信息:

在此处输入图片说明

With no directory names. 没有目录名称。 So do I have to manually make those directories, and then will android automatically pick the right image to use depending on the screen size? 那么,我是否必须手动创建这些目录,然后android会根据屏幕尺寸自动选择合适的图像使用吗?

I have the same question for the layout. 我对布局也有同样的疑问。 For example, I know that to support many screen sizes, I need to put the layout in many folders like this: 例如,我知道要支持多种屏幕尺寸,我需要将布局放在许多文件夹中,如下所示:

在此处输入图片说明

But right now, my layout is like this: 但是现在,我的布局是这样的:

在此处输入图片说明

So must I manually create each layout folder, and then copy and paste my current layout into the new layout folder, and then go into each layout, and render it until it looks nice on the android design tab of the XML? 因此,我是否必须手动创建每个布局文件夹,然后将当前布局复制并粘贴到新的布局文件夹中,然后进入每个布局并进行渲染,直到在XML的android design选项卡上看起来不错? Then, will android pick out the best layout depending on the screen size for me? 然后,Android是否会根据我的屏幕尺寸选择最佳布局?

I also get this when trying to make a new layout. 当尝试进行新的布局时,我也会得到这个。 What to fill in? 填写什么?

在此处输入图片说明 Thanks so much, 非常感谢,

I have been delaying making my app compatible in different layouts because of these questions, I hope they can get answered! 由于这些问题,我一直在推迟使我的应用程序在不同布局中兼容,我希望它们能够得到解答!

You can create different layout folders and create layouts for standard screen sizes. 您可以创建不同的布局文件夹并为标准屏幕尺寸创建布局。 There is a set of six generalized densities: 有一组六种广义密度:

ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi

You can create images and layouts for these and use accordingly.Mention that in you manifest also: 您可以为它们创建图像和布局并相应地使用。

<compatible-screens>
    <screen
        android:screenDensity="ldpi"
        android:screenSize="small" />
    <screen
        android:screenDensity="mdpi"
        android:screenSize="normal" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="large" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="xlarge" />        
</compatible-screens>

Refer Supporting Multiple Screens for more details 有关更多详细信息,请参阅支持多屏

There are some tips : 有一些技巧:

  1. Don't hard code any layout parameters such as width,height,etc.. 不要硬编码任何布局参数,例如宽度,高度等。
  2. Don't use "px".Use "sp" for font sizes and "dp" for layout-width, layout-height etc. 不要使用“ px”。将“ sp”用于字体大小,将“ dp”用于布局宽度,布局高度等。
  3. Make use of RelativeLayout and LinearLayout and don't use AbsoluteLayout as it is deprecated. 使用RelativeLayoutLinearLayout ,不要使用AbsoluteLayout因为它已弃用。
  4. Use ScrollView wherever required for layouts as it supports for a single view. 布局所需的任何地方都可以使用ScrollView ,因为它支持单个视图。

yes you have to make different layout folders for different screen sizes like layout-sw480dp , layout-sw600dp like that for different screen sizes and for landscape view use layout-landscape . 是的,你必须做出不同的屏幕尺寸就像不同的布局文件夹layout-sw480dplayout-sw600dp一样,对于不同的屏幕尺寸和横向视图使用layout-landscape and you have to use drawable-hdpi , drawable-mdpi , drawable-ldpi , drawable-xhdpi etc to put different resoultion images for different screeen resolution devices 并且您必须使用drawable-hdpidrawable-mdpidrawable-ldpidrawable-xhdpi等来为不同的屏幕分辨率设备放置不同的显示图像

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

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