FrameLayout with gravity=center?

Hello everyone Let's say I have a FrameLayout in which all View should be in the center. Which attribute FrameLayout will set all View to the center? So far, I set all child elements to

android:layout_gravity="center"

Is this the only way?

Author: Lex Hobbit, 2017-08-01

2 answers

If you need exactly FrameLayout, then only as you are doing it now. Otherwise, you can use RelativeLayout, which supports the {[3] parameter.]}:

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView is in center of parent"/>

</RelativeLayout>
 2
Author: eugeneek, 2017-08-01 07:01:49
<FrameLayout android:id="@+id/CompassMap"
               android:layout_width="fill_parent" 
               android:layout_height="wrap_content"
               android:layout_weight="1"
               android:gravity="center"> // нужный параметр
///////
</FrameLayout>
 -1
Author: Andriy Martsinkevych, 2017-08-01 06:15:55