Android official Getting Started document [10] supports different screens supporting Different Screens
Support for different screens
This lesson teaches
1.Create Different Layouts
2.Create Different Bitmaps
You should also read
? Designing for multiple Screens
? Providing Resources
? Iconography Design Guide
This lesson teaches you
1. Create a different layout
2. Create a different bitmap
You should also read
? design for multi-screen
? provide resources
? Imaging Design Guide
android categorizes device screens using both general properties:size and density. You should expect that your app would be installed on devices with screens that range in both size and density. As such, you should include some alternative resources, the optimize your app ' s appearance for different screen sizes and Densities.
? There is four generalized sizes:small, normal, large, XLarge
? and four generalized densities:low (ldpi), Medium (MDPI), High (hdpi), Extra High (XHDPI)
Android classification using two general properties device screen: size and density 。 You should expect your application to be installed with screens, ranges of devices in scale and density. Therefore, you should include some alternative resources that optimize the appearance of your application with different screen sizes and densities.
? There are four common sizes: small, normal, large, xlarge (small, regular, large, oversized)
? With 4 generalized density: Low (ldpi), Medium (MDPI), High (hdpi), Extra High (xhdpi)
To declare different layouts and bitmaps you ' d like to use for different screens, you must place these alternative RESOURC ES in separate directories, similar-to-do-for-different language strings.
declaring different layouts and bitmaps that you want to use on different screens, you have to put these alternative resources in different directories, similar to how you do different language strings.
Also be aware that the screens orientation (landscape or portrait) are considered a variation of screen size, so many apps Should revise the layout to optimize the user experience in each orientation.
Also note that the screen orientation (landscape or portrait) is considered a change in screen size, so many applications should modify the layout to optimize the user experience in each direction.
Create Different Layouts
Create a different layout
--------------------------------------------------------------------------------
to optimize your user experience on different screens sizes, you should create a unique LA yout XML file for each screen size, want to support. Each layout should is saved into the appropriate resources directory, named with a-<screen_size> suffix. For example, a unique layout for large screens should is saved under res/layout-large/.
to optimize the user experience on different screen sizes, you should create a layout XML file that is unique to each screen size you want to support. Each layout should be saved to the appropriate resource directory, named the-<screen_size> suffix. For example, a unique layout for a large screen should be saved in res/layout-large/.
Note:android automatically scales your layout in order to properly fit the screen. Thus, your layouts for different screens sizes don ' t need to worry on the absolute size of UI elements but instead focus On the layout structure this affects the user experience (such as the size or position of important views relative to Sib Ling views).
Note: Android automatically scales your layout to fit the screen properly. As a result, your layout's different screen sizes don't have to worry about the absolute size of the UI elements, but instead focus on the layout structure, which affects the user's experience (such as the size or opinion of the important position relative to the sibling).
For example, the This project includes a default layout and the alternative layout for large screens:
For example, the project includes a default layout and an alternate layout for large screens:
myproject/
res/
layout/
Main.xml
layout-large/
Main.xml
The file names must is exactly the same, but their contents is different in order to provide a optimized UI for the Corr esponding screen size.
Filenames must be exactly the same, but their content is different for providing a user interface that is optimized for the appropriate screen size.
Simply reference the layout file in your app as usual:
As always, simply reference the layout file in your application:
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}
The system loads the layout file from the appropriate layout directory based on screen size of the device on which your AP P is running. More information on how Android selects the appropriate resource are available in the providing Resources guide.
The system loads a directory layout file from the appropriate layout based on the screen size of the device on which the application is running. For more information on how Android chooses the right resources, please provide a resource guide.
As another example, here's a project with the alternative layout for landscape orientation:
To give another example, here is a project with a landscape alternative layout:
myproject/
res/
layout/
Main.xml
layout-land/
Main.xml
By default, the Layout/main.xml file was used for portrait orientation.
By default, files in Layout/main.xml are used for portrait orientation.
If you want to provide a special layout for landscape, including and on large screens and then you need to use both the Lar GE and Land Qualifier:
If you want a special layout for the landscape, including both on the big screen, then you need to use both the large and land qualifiers:
myproject/
res/
layout/ # Default (Portrait)
main.xml
layout-land/ # Landscape
Main.xml
layout-large/ # Large (portrait)
main.xml
layout-large-land/ # Large Landscape
main.xml
Note:android 3.2 and above supports an advanced method of defining screens sizes that allows you to specify resources for Screen sizes based on the minimum width and height in terms of density-independent pixels. This lesson does isn't cover this new technique. For more information, read designing for multiple Screens.
Note: Android 3.2 and above support the advanced method of defining screen size, which allows you to specify the screen size of resources based on the minimum width and height of the density-independent pixels. This class does not include this new technology. For more information, read the multiple screens of your design.
Create Different Bitmaps
Create a different bitmap
--------------------------------------------------------------------------------
You should all provide bitmap resources that is properly scaled to each of the generalized density Buckets:low, Mediu M, high and extra-high density. This helps your achieve good graphical quality and performance on all screens densities.
You should always provide appropriate scaling to each of the generalized density bucket bitmap resources: Low, medium, high, ultra high density. This will help you achieve good graphics quality and performance on all screen densities.
To generate these images, you should start with your raw resource in vector format and generate the images for each densit Y using the following size scale:
? xhdpi:2.0
? hdpi:1.5
? mdpi:1.0 (Baseline)
? ldpi:0.75
To produce these images, you should have the original resources from your vector format, resulting in a density image using the size of the following dimensions:
? xhdpi:2.0
? hdpi:1.5
? mdpi:1.0 (Baseline)
? ldpi:0.75
This means so if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for HD Pi, 100x100 for mdpi, and 75x75 for ldpi devices.
This means that if you generate a 200x200 image xhdpi device, you should generate LDPI devices with the same resources in 150x150 hdpi,100x100 and MDPI.
Then, place the files in the appropriate drawable resource directory:
Then, the files in the appropriate drawing resource directory are:
myproject/
res/
drawable-xhdpi/
Awesomeimage.png
drawable-hdpi/
Awesomeimage.png
drawable-mdpi/
Awesomeimage.png
drawable-ldpi/
Awesomeimage.png
Reference @drawable/awesomeimage, the system selects the appropriate bitmap based on the screen ' s density.
You reference @drawable/awesomeimage any time, the system chooses a bitmap based on the appropriate density of the screen.
Note:low-density (ldpi) resources aren ' t always necessary. When you provide HDPI assets, the system scales them down by one half to properly fit ldpi screens.
Note: Low density (ldpi) resources are not always necessary. When you go to the HDPI resource, the system is scaled down by a half-to-right ldpi screen.
For more tips and guidelines on creating icon assets for your apps, see the Iconography Design Guide.
For more tips and guidelines on the icon assets created by your application, see the Video Design Guide.
This article is translated from: https://developer.android.com/training/basics/supporting-devices/screens.html
Android official Getting Started document [10] support for different screens