Android multiple screen sizes with same density

后端 未结 6 810
你的背包
你的背包 2020-11-29 16:49

I\'m confused regarding the densities. I see that with medium density, the screen resolution could be either 320x480, 480x800, or 480x854. So if I have an image thats 300px

6条回答
  •  离开以前
    2020-11-29 17:24

    For completeness, also check these option for controlling layout:

    Directory qualifiers:

    Size:         small, normal, large
    Density:      ldpi, mdpi, hdpi, nodpi(no auto-scale)
    Aspect ratio: long, notlong
    Orientation:  land
    
    Usage:

    res/layout/my_layout.xml            
    res/layout-small/my_layout.xml      
    res/layout-large/my_layout.xml      
    res/layout-large-long/my_layout.xml      
    res/layout-large-land/my_layout.xml     
    res/drawable-ldpi/my_icon.png  
    res/drawable-mdpi/dpi/my_icon.png  
    res/drawable-hdpi/my_icon.png      
    res/drawable-nodpi/composite.xml   
    

    Restricting your app to specific screen sizes(via the AndroidManifest):

    
    ...
    
    ...
    

    And for code level tweeking:

    float scale = getContext().getResources().getDisplayMetrics().density;
    
    And don't forget:

    dpi    = 160; //At 160dpi
    pixels = dips * (density / dpi)
    

    It's all in this doc: developer.android.com:Supporting Multiple Screens

提交回复
热议问题