Alternative to Absolut Layout

Asked

Viewed 69 times

1

I saw that the AbsoluteLayout has been discontinued for reasons of standards on different phones. Currently use the RelativeLayout, but if by it keep the objects in relative positions, if I change one, the whole rest is changed.

Is there any substitute for AbsoluteLayout that allows me to freely move the components without altering the position of others?

  • Don’t even think about using absolute layout. With 500 thousand xinglings phones of various screen patterns? And many of them do not follow patterns? Meet Framelayout and be happy :-)

2 answers

3


Fala Gustavo,

When you use Relativelayout, you must specify which item is on top of 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 Textview, and Gustado Rotondo, will be below Leonardo Dias.

And so you control, there are other options too:

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

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

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

Thus, all items will fit one below the other.

I hope I’ve been able to explain it better.

Hugs.

1

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

But it is not recommended that you work with fixed positions of view, because they won’t be positioned the same way in devices with different screen sizes.

Browser other questions tagged

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