When to use Relative or Linear Layout?

Asked

Viewed 64 times

0

I’m wondering when to wear it LayoutRelativo or Linear? What advantage to use in each case.

  • take a look here

  • Never, always use ConstraintLayout

1 answer

1

Linearlayout

It is indicated when you want to align the components in series, whether vertical or horizontal. The following image shows a layout with horizontal orientation (the 3 components are side by side):

Exemplo de componentes em um LinearLayout

Source: Android Developers


Relativelayout

It serves to position the components so that one is relative to the other. The following image shows this, with the first component aligned to the top, another two below it, one to the left and the other to the right of the parent layout:

Exemplo de componentes em um RelativeLayout

Source: Android Developers


Recommending

Is available the ConstraintLayout, which is a significant development of RelativeLayout. It allows much more flexibility in development, and is recommended in favor of the aforementioned alternatives.

Another option is the CoordinatorLayout, very useful in the composition of layouts it contains AppBars and/or FloatingActionButtons, facilitating the creation of more responsive animations and components.

Browser other questions tagged

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