V
V
Vetal Matitskiy2016-03-02 10:00:08
Android
Vetal Matitskiy, 2016-03-02 10:00:08

Why is xml for android so ugly looking and are there any alternatives?

I started taking a course on android and was unpleasantly surprised by the xml code for describing the visual part. the code, as for me, causes an extremely dumb feeling - a hodgepodge of camel case and snake case. individual attributes are effectively compound fields. the logic behind the formation of names is extremely mysterious. Is it just me, or have others experienced it too? Are there any alternatives that allow you to write on something more adequate?
just found an example: layout_margin vs padding - why in one case there is layout in the title, and in the other there is not...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2016-03-02
@zagayevskiy

In android, parameters prefixed with layout_ are used by the "parent" view (i.e. the enclosing ViewGroup, such as Linear/Relative/FrameLayout) in order to properly position the view. They are stored in LayoutParams, this is a separate class, different for each ViewGroup. For example, in CoordinatorLayout.LayoutParams there is layout_behaviour - it sets the behavior for this view.
And the parameters without such a prefix are used by the view itself (for example, padding - how far the content is from the borders. The parent view does not know anything about this, it does not need it).
From a philosophical point of view, this is, of course, a hodgepodge, but in practice, you quickly start filtering all these layout_.
There is only one alternative - to write layouts in the code, but this is a bad idea.

R
razer89, 2016-03-02
@razer89

Quite a normal xml, you get used to it quickly enough. I haven't seen any viable alternatives. At the expense of layout in the title - this means that the attribute will be applied to the parent container (if possible). For example, gravity="right" means that the container will align its content to the right, layout_gravity will try to align the container itself in the parent element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question