简体   繁体   中英

How to handle multiple screen formats with the same screen size layout?

I already read the entire android documentation about this and i still didnt manage to do this in the right way.

I will explain better.

I have 3 different devices, a 480x320 a 640x480 and the 800x480. The problem is that these 3 devices uses my normal layout, in other words only one of them will fit okay.

I am already using dp instead of px and i have all sized of images for all kinds of screens densities but the problem is that i make a lot of layouts with margin and spaces between the views so when i put in the 800x400 phone it lays perfectly but in the others a large piece of the screen is like cutted...

I searched for this and i really dont know what to do, i need a way to manage all the screen sizes in this same project.

Please does anyone has any idea how to make this right?

To manage your layout effectively follow following guidelines.

1). Always try to use RelativeLayout in your XML as RelativeLayout adjust views according to your screen size.

2). Instead of creating Layouts for all size screen try to use Dimensions for all screen size and create single Layout.(Creating Dimension will reduce you lots of work and effort)

  • use gravity - tell your layout elements to go to right/left/top/bottom/center in their container. You should of course group them by meaning
  • don't use dp unless it's for text size or the total value is less then the minimum supported size. Let your views have dynamic size based on their content (wrap_content) or fill the parent (match_parent)
  • in case you need dp value for some text size - use a <dimen> resource to define different size for different screens (same resource placed in multiple values-... folders)
  • in addition to the gravity attribute use layout_weight in your layout to let it's children occupy fixed % of the layout's space

EDIT: You have written that you've read the documentation but I'd like to mention that Providing Resources and Supporting Multiple Screens are the absolute minimum in my opinion. Don't forget their "Best practices" sections too.

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