简体   繁体   English

如何在Android上处理不同的屏幕分辨率?

[英]How to handle different screen resolutions on Android?

Nexus 10 holds 2500*1600 resolution whereas the previous neighbor in the same density family holds 1024*800 - ** DOUBLE ** Nexus 10的分辨率为2500 * 1600,而同一密度系列中的前一个邻居的分辨率为1024 * 800-**双**

My concern is completely on images, I already hold images of x*x px, If I use the same image in Nexus - it stretches ? 我的担心完全在图像上,我已经保存了x * x px的图像,如果我在Nexus中使用相同的图像-它会拉伸吗?

How to handle these type of resolutions ? 如何处理这些类型的决议?

There are many possible ways to achieve this one of the major thing is using components size 有很多可能的方法来实现这一目标,其中之一就是使用组件大小

width -- height in dp, text size in sp 宽度-以dp为单位的高度,以sp为单位的文字大小

other is you can use layout-ldpi, layout-mdpi, layout-hdpi, layout-xhdpi 其他是您可以使用layout-ldpi,layout-mdpi,layout-hdpi,layout-xhdpi

dp and sp will solve your problem dp和sp将解决您的问题

http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

You should have alternative resources depending on screen resolution. 您应该具有替代资源,具体取决于屏幕分辨率。

For example if you want alternative layout for extra large screens, you need to place the alternative layouts in layout-xlarge. 例如,如果您想要超大屏幕的替代布局,则需要将替代布局放置在layout-xlarge中。 The general rule is resources_name-qualifier. 一般规则是resources_name-qualifier。 You can find out about the options in the android guide for supporting multiple resolutions and screen sizes: http://developer.android.com/guide/practices/screens_support.html 您可以在android指南中找到有关支持多种分辨率和屏幕尺寸的选项的信息: http : //developer.android.com/guide/practices/screens_support.html

Arun chandravanshi 阿伦·钱德拉万史

Handle multiple resolutions in android: 在android中处理多种分辨率:

1) In android Application project anatomy 4 folder 1) hdpi,mdpi,ldpi and xhdpi (in res folder ) you can put your images here for multiple screen size devices. 1)在android Application project anatomy 4文件夹中1)hdpi,mdpi,ldpi和xhdpi(在res文件夹中),您可以将图像放置在此处以用于多个屏幕尺寸的设备。 The system automatically choose images from these folder according to device. 系统会根据设备自动从这些文件夹中选择图像。

2) use sp instead of dp when give font size. 2)指定字体大小时,请使用sp而不是dp。

3) us dp in place of px. 3)我们用dp代替px。

4) Mostly us Linear layout and Relative layout instead of other layout. 4)通常我们使用线性布局和相对布局,而不是其他布局。

5) Use 9 patch images. 5)使用9个补丁图像。

6) Avoid using of Absolute layout. 6)避免使用绝对布局。

7) use png images. 7)使用png图片。

8) use layout-land folder for landscape mode. 8)将layout-land文件夹用于横向模式。

Thanks. 谢谢。

you can determine the size of the screen by code and then apply the necessary code. 您可以通过代码确定屏幕的大小,然后应用必要的代码。 for example, I need to change text size base on different screen resolution. 例如,我需要根据不同的屏幕分辨率更改文本大小。

public void setMainButtonTextSize(){
    if (isXLargeScreen()){
        mainButtonTextSize = 38;
        mainButtonDownTextSize = 32;
        titleTopButtonTextSize = 80;
        titleBottomButtonTextSize = 60;
        timeTextSize = 36;
        dayTextSize = 26;
        dateTextSize = 36;

    } else if (isLargeScreen()){
        mainButtonTextSize = 28;
        mainButtonDownTextSize = 22;
        titleTopButtonTextSize = 70;
        titleBottomButtonTextSize = 50;
        timeTextSize = 26;
        dayTextSize = 16;
        dateTextSize = 26;
    } else if (isNormalScreen()){
        mainButtonTextSize = 18;
        mainButtonDownTextSize = 14;
        titleTopButtonTextSize = 40;    
        titleBottomButtonTextSize = 30;
        timeTextSize = 16;
        dayTextSize = 12;
        dateTextSize = 16;
    }  else if (isSmallScreen()){
        mainButtonTextSize = 12;
        mainButtonDownTextSize = 10;
        titleTopButtonTextSize = 30;
        titleBottomButtonTextSize = 20;
        timeTextSize = 12;
        dayTextSize = 8;
        dateTextSize = 12;
    }
} 


public Boolean isLargeScreen(){
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
        return true;
    } else 
        return false;       
}

public Boolean isNormalScreen(){
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
        return true;
    } else 
        return false;       
}

public Boolean isSmallScreen(){
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
        return true;
    } else 
        return false;       
}

public Boolean isXLargeScreen(){
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        return true;
    } else 
        return false;       
}

depending on the return value, i change the text size accordingly. 根据返回值,我相应地更改文本大小。

The points in this thread are generic tips to design layouts for multiple screen- 该主题中的要点是设计多屏布局的通用提示,

I got the answer - 我得到了答案-

We can even sub categorize the drawable's depending on resolution using drawing-sw1200-xhdpi 我们甚至可以使用drawing-sw1200-xhdpi根据分辨率对可绘制对象进行分类。

Regards SS 关于SS

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

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