Why should we use xml layouts?

After several years of Android development, for several months I wondered why I should use xml layouts to create the user interface of my Android application.

I understand this part of the MVC design and real-time GUI.

If I'm wrong, please take me out of ignorance and forgive me, but I canโ€™t set the view position to exactly 8% of the screen width for the field and 70% of the screen width for the width, for example.

Creating a user interface in this way and observing the proportions of the screen ensures that the application will look proportionally exactly the same on all devices.

As this post sums up, we are told to use dip units and a nice bunch of xml files for each layout of our application, if we want to support different screens. (Why do they call it density independent if we need to make it different for each screen density?)

But even doing it like (again) Google Doc says

The dp-to-pixel ratio will vary with screen density, but not necessarily in direct proportion.

And instead of not necessarily, they should say, basically, never looking at an incredible amount of different devices. This may be a problem depending on your project. (Or do you want your client to look at your "slightly laid out" user interface on those who know the Chinese device).

I could ask the same for image resources, but this will be another question I use to set the maximum resolution to -nodpi, then decrease with the code to the required size depending on the screen width, instead of putting 10,000 images general resolution.

0
source share
1 answer

Creating a user interface in this way and caring for the screen format ensures that the application will look proportionally the same in all devices.

This is the way Apple does, and so when you open the folder on the 9.7-inch iPad with a beautiful retina display, it only displays 9 icons.

A tablet is not just a big phone. This is really not the case. In addition, iOS devices have basically the same aspect ratio, so they take care of the aspect ratio.

On Android, however, you cannot just say that you โ€œtook care of the aspect ratioโ€ and that this problem magically goes away. Itโ€™s best to use the best Android methods to properly handle aspect ratios.

Speaking of this, do not do this. For example, you do not need to use all 8 density buckets. Take a look at the official dashboard to see which devices are actually used before trying to optimize for each scenario.

In addition, you do not need to constantly listen to Google. For example, Iโ€™m sure that Google will love that you translate your application so that it is available in more than 68 languages โ€‹โ€‹of different countries around the world, but what benefit for Google is not always good for you. Android actually allows you to choose the tools you want to use to create your application. They do not force you to use any particular one.

+3
source

Source: https://habr.com/ru/post/1236686/


All Articles