Difference between frame and relative layout?

I'm new to Android programming, but from how I understood the layouts from the documentation , RelativeLayout is mostly used when you need views based on some rules and FrameLayout when you want to overlap views.

But unfortunately, for the next program, I get FrameLayout working with RelativeLayout. I did my job, but for understanding, did I miss something in the difference? Also, how did the buttons paint my image? (Even another image overlaps.)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/imageView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/ic_launcher" /> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ic_launcher" android:layout_alignParentTop="true" android:layout_alignLeft="@id/imageView1" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBottom="@+id/imageView1" android:gravity="center" android:orientation="horizontal" android:weightSum="1.0" > <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.33" android:text="Login" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.33" android:text="Register" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.33" android:text="Try application" /> </LinearLayout> </RelativeLayout> 
+6
source share
3 answers

RelativeLayout can use:

 android:layout_toEndOf="@id/some_view" android:layout_toStartOf="@id/some_view" android:layout_above="@id/some_view" android:layout_below="@id/some_view" 

to ensure that the view strings are correctly connected to each other. FrameLayout very similar, except that it uses only gravity to display its representations (without relation).

I would also suggest you take a look at the ConstraintLayout component. ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (without nested view groups). It looks like RelativeLayout in that all the views are laid out in accordance with the relationship between the sister's views and the parent layout, but it is more flexible than RelativeLayout and easier to use with the Android Studio layout editor.

+16
source

RelativeLayout based on attitude views. This is a layout manager that helps you organize user interface elements based on some rule. You can specify things like: align it with the left edge of the parents, put it left / right of these elements, etc.

FrameLayout allows placement on the Z axis. That is, you can stack presentation elements one above the other.

+8
source

RelativeLayout. As the name implies in this viewing group, the view is positioned relative to each other. Most of the used relativelayout properties are used:

 android:layout_toLeftOf="@id/some_view1" android:layout_toRightOf="@id/some_view2" android:layout_above="@id/some_view3" android:layout_below="@id/some_view4" android:layout_toendof="@id/some_view5" android:layout_tostartof="@id/some_view6" 

The view is placed relative to each other. This is really useful when developing a complex.

FrameLayout - it behaves because the representation of one object does not fit relative to each, but according to FrameLayout. FrameLayout takes the size of the largest child view.

 android:gravity="center_horizontal|center_vertical|bottom" 

The use of the upstream position of the child views has been changed.

0
source

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


All Articles