Running on Multiple Screens

Asked

Viewed 694 times

2

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

It is possible or would have to create specific Layouts?

  • Layout you have to create always, what is possible is to call a Layoutin a Fragment, as far as I know.

2 answers

4

The Android Resources system will choose the most suitable layout for the device screen according to the layout-small directories, layout-normal, layout-large and layout-xlarge. In addition, you can also have the definitions by orientation with the qualifiers land and port. And 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 the design of your screens stay on larger and smaller screens, and you are not required to have all combinations for layout.

For example, if you think that for small, normal and large screens the same layout applies, and want to create only one special for tablets, you would then need a layout folder and another layout-xlarge. Thus, all which are large "down" would use the layout 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 the different devices have different pixel densities. So, if you make just one image for all densities, you can have very large images on one screen and very small images on other.

But, that doesn’t mean you have to have layouts for each image size. Because the layouts are responsible for the organization of the elements on the screen. For the images, you will use the drawable folder with the density qualifiers ldpi, mdpi, hdpi, xhdpi and etc.

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

1

If what you want is to use the same layout on multiple screens (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, will be using Fragments.
In addition to reuse the 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 on device in question.

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

  • Ramaral, I mean to use the layout in different Vices. This is a difficulty even if I find in the development of the Android platform, having to provide a layout for numerous devices. Thanks for the help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.