My XML design does not apply to all Android devices?

In my project, my design works well in my Android HTC 2.3.4, but my screen is not displayed completely in 4.0.1 (some designs are cut from the bottom) .Why?
Since you haven’t posted any code yet, I will briefly introduce the Android layout and resources.

You have to create multiple resources for your app. Android has 4 resolutions (ldpi, mdpi, hdpi and xhdpi) and 4 common screen sizes (small, medium, large, and extra large). Therefore, you You must make 4 layouts (if you don’t plan to support tablets, you need 3 layouts because tablets are in the super-large category) to support the screen size.

This is a general guideline:

Place small, medium, large and super large layouts in the res/ folder, as shown below:

res/layout/sample_layout.xml // default layout
res/layout-small/sample_layout.xml // layout for small screen size
res/layout-large/sample_layout.xml // layout for large screen size
res/layout-xlarge/sample_layout.xml / / layout for extra large screen size

You can also use

res/layout-land/sample_layout.xml for the horizontal orientation of all screen sizes, or you can use specific screen sizes The horizontal layout is positioned as res/layout-medium-land/sample_layout.xml

Please note that all layouts have the same name.

After preparing the layout, you also need to process the image Resolution

Add the following image to your res/ folder again:

res/drawable-ldpi/sample_image.png // low density< br />res/drawable-mdpi/sample_image.png // medium density
res/drawable-hdp i/sample_image.png // high density
res/drawable-xhdpi/sample_image.png // extra high density

Again, all images have the same name.

The general guidelines for designing images are:

ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi

Usually, I design mdpi images for 320×480 screens, and then multiply the sizes to obtain images of other resolutions according to the above rules.

Android will automatically select the layout and The best combination of images. For example, for high-resolution medium-sized devices, the layout will be shown to the user – medium-density and high-density images.

Make sure to create simulators for all these combinations and thoroughly test your application Program. Here is the official document for more information:

https://developer.android.com/guide/practices/screens_support.html

In my project, my design works well in my Android HTC 2.3.4, but my screen is not displayed completely in 4.0.1 (some designs are cut from the bottom). Why?

Since you haven’t posted any code yet, I will briefly introduce the Android layout and resources.

You must create multiple Resources. Android has 4 resolutions (ldpi, mdpi, hdpi and xhdpi) and 4 universal screen sizes (small, medium, large and super large). Therefore, you must make 4 layouts (if you don’t plan to support tablets For computers, you need 3 layouts, because tablets belong to the super-large category) to support the screen size.

This is a general guideline:

Place small, medium, and small in the res/ folder The large and super large layouts are as follows:

res/layout/sample_layout.xml // default layout
res/layout-small/sample_layout.xml // layout for small screen size
res/layout-large/sample_layout.xml // layout for large screen size
res/layout-xlarge/sample_layout.xml // layout for extra large screen size

< p>You can also use

res/layout-land/sample_layout.xml for the horizontal orientation of all screen sizes, or you can position the horizontal layout of a specific screen size as res/layout-medium-land /sample_layout.xml

Please note that all layouts have the same name.

After preparing the layout, you also need to deal with the image resolution

Add the following image to the res/ folder:

res/drawable-ldpi/sample_image.png // low density
res/drawable-mdpi/sample_image.png // medium density
res/drawable-hdpi/sample_image.png // high density
res/drawable-x hdpi/sample_image.png // extra high density

Again, all images have the same name.

The general guidelines for designing images are:

ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi

Usually, I design mdpi for 320×480 screens Image, and then multiply the size according to the above rules to obtain images of other resolutions.

Android will automatically select the best combination of layout and image according to the device. For example, for high-resolution medium-sized devices, Show the user the layout – medium density and high density images.

Make sure to create simulators for all these combinations and thoroughly test your application. Here is the official document for more information:

https://developer.android.com/guide/practices/screens_support.html

Leave a Comment

Your email address will not be published.