简体   繁体   中英

how to set layout for different screen size in android

I am working on a app in which there are some textfiels and button when I am running it on different screen size devices it is showing unexpected result as shown in the below image!

[Image 1] http://oi45.tinypic.com/25yvon4.jpg [Image 2] http://oi45.tinypic.com/xmlqns.jpg

Here in first image some space is left vacant at the bottom due to large screen size and in second image the last row of buttons are hidden due to small screen size.Also for buttons I am using Table Layout.

Is there any way to solve this problem.

That's a broad topic that needs spatial understanding first. Here's a good place to start - http://developer.android.com/guide/practices/screens_support.html

Long story short, always use point units (dps), try to avoid to hardcoded pixels within your code, position items in a relative way (ie.: in relation to other object - RelativeLayout, LinearLayout, etc) and make sure to take advantage of the power of "values-..." folders. Example

values-xhdpi (XH)

values-hdpi (H)

values-mdpi (M)

values-land (Landscape)

values-sw600dp (smallest width at least 600dp)

....

Use layout, layout-large and layout-xlarge resource folders to customize your layout files if you care about various screen sizes. Test these layouts on phones, 7" and 10" tablets to cover all of your bases.

For small phones of less than 4" screens (qvga) as well as older devices (wvga), make custom layout files (in the layout folder) and refer to them dynamically in your java code when you detect these kinds of devices. Again, test on these older & smaller phones as much as possible. Borrow some phones from the Sony Device Loaner Program in order to get real-world testing done.

Lastly, use ScrollView to embed your layouts if you want vertical scrolling on smaller screens. Don't go crazy trying to fit everything on a smaller screen. Sometimes scrolling is a natural solution that your users will understand.

You must have to make screen for all devices if you want to solve your problem.Read below document for different screen:-

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

or

You can use weight or layout weight to prevent this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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