Running on Multiple Screens

2

How to define a layout to run on multiple screens without having to create multiple Layouts?

Is it possible or would you have to create specific Layouts?

    
asked by anonymous 06.02.2014 / 12:35

2 answers

4

The Android resource system will choose the most appropriate layout for the device screen according to the layout-small, layout-normal, layout-large, and layout-xlarge directories. In addition, you can also have the settings by orientation with the land and port qualifiers. And you can combine size and orientation.

So it's up to you developer to create the layouts according to the screens you need. The way is to test and see how your screen designs get on larger and smaller screens, and you're not required to have all the layout combinations.

For example, if you think that for small, normal and large screens the same layout applies, and you want to create only one special for tablets, you would then need a layout folder and another layout-xlarge. Thus, all that are large "down" would use the layout in the layout folder and only the specific size would be used the layout-xlarge.

In addition, you need to pay attention to the size of the images used as well, as different devices have different pixel densities. So if you only make one image for all densities, you can have very large images on one screen and very small on others.

But, that does not mean that you have to have layouts for each image size. Because layouts are responsible for organizing the elements on the screen. For images, you will use the drawable folder with the density qualifiers ldpi, mdpi, hdpi, xhdpi, and so on.

In the official Android documentation there is a dedicated guide to detailing qualifiers, best practices, and everything else you need to know to support multiple screens. Take a look at the Supporting Multiple Screens guide

    
10.02.2014 / 04:00
1

If you want to use the same layout in several layouts, you just have to create an xml with the layout you want to reuse, and on the screen where you want to use it, put this command:

<include layout="@layout/nome_do_layout" />  

Better yet, as Felipe Avelar suggests, it will use Fragments . In addition to reusing layout , you reuse the code associated with it.

If you refer to using the layout in different devices , with different densities and dimensions, the answer is yes. Of course this only applies if you find that the layout does not look good in the device in question.

Whenever you use images or icons, you must have one for each density

    
06.02.2014 / 12:41