My Xml design not working in all android Devices?

北城余情 提交于 2019-11-27 13:22:17

问题


In my project, My Design is working fine in my android HTC 2.3.4 But on 4.0.1 my screen is not showing full ( Some design is cutting from Bottom). Why?


回答1:


Since you haven't posted any code, I'll just give you a brief overview of android layouts and resources.

You have to create multiple resources for your app. Android has 4 resolutions (ldpi,mdpi,hdpi and xhdpi) and 4 generalized screen sizes (small, medium, large and extra large). So you have to make 4 layouts (or 3 if you don't plan on supporting tablets, since tablets come under the extra large category) to support the screen sizes.

Here's a general guide:

put layouts for small, medium, large and extra large in your res/ folder 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

you can also use

res/layout-land/sample_layout.xml for landscape orientation for all screen sizes or you can target landscape layouts for specific screen sizes as res/layout-medium-land/sample_layout.xml

note that all the layouts have the same name.

once you have your layouts ready, you need to take care of image resolutions also

once again in your res/ folder add images like this:

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-xhdpi/sample_image.png        // extra high density

once again, all the images have the same name.

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

generally, I design mdpi images for a 320x480 screen and then multiply the dimensions as per the above rules to get images for other resolutions.

Android will automatically select the best combination of layout and image depending on the device. For example, for a high resolution medium size device, layout-medium and high density image will be displayed to the user.

Make sure you create emulators for all these combinations and test your app thoroughly. here's the official docs for more info:

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




回答2:


here i am sending you a document for the devices screens and densitites it will help you to understand which device will take image from which folder...!




回答3:


One layout doesn't always work for all the various screen sizes. Since android has at least 4 different screen sizes (small, medium, large, extra large) You will either need to use dp (density pixels) in a smart way, or have a different layout for each screen resolution (which i personally reccomend)

The way you do this is create folder for each type of layout you want, as shown below. Quote from http://developer.android.com/guide/practices/screens_support.html : For example, the following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.

res/layout/my_layout.xml // layout for normal screen size ("default")

res/layout-small/my_layout.xml // layout for small screen size

res/layout-large/my_layout.xml // layout for large screen size

res/layout-xlarge/my_layout.xml // layout for extra large screen size

res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

you can also just use

<supports-screens android:smallScreens="false" 

in your manifest in order to choose which screen sizes you want it available on. But then people won't be able to download it from the store at all if they have a different size screen



来源:https://stackoverflow.com/questions/12742792/my-xml-design-not-working-in-all-android-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!