Alternative to Absolut Layout

1

I saw that AbsoluteLayout was discontinued because of patterns on different phones. I currently use RelativeLayout , but if it keeps the objects in relative positions, if I change one, the rest everything changes.

Is there a substitute for AbsoluteLayout that lets me freely move components without changing the position of others?

    
asked by anonymous 27.06.2016 / 14:20

2 answers

3

Gustavo speaks,

When you use RelativeLayout, you must specify which item is over which, for example:

<TextView
    android:id="@+id/name_dias"
    android:text="Leonardo Dias"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<TextView
    android:id="@+id/name_rotondo"
    android:text="Gustavo Rotondo"
    android:layout_below="@id/name_dias"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

I have two TextViews, and Gustado Rotondo will be under Leonardo Dias.

And so you control, there are other options too:

  • android: layout_toRightOf="@ id / name_dias" (left)
  • android: layout_toLeftOf="@ id / name_dias" (right)
  • android: layout_above="@ id / name_days" (above)

And you can also use LinearLayout, when you define it, you must specify a vertical or horizontal orientation, and the items themselves will fit together:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

So, all of the items fall under each other.

I hope I have been able to explain it in the best way.

Hugs.

    
27.06.2016 / 14:28
1

Gustavo, you can continue using RelativeLayout and set the margin of the component to position it wherever you want, it's the only alternative to AbsoluteLayout where you fixed it in the place you wanted.

But it is not recommended that you work with fixed positions of view , as they will not be positioned in the same way on devices with different screen sizes.

    
27.06.2016 / 14:42