Hello! Suppose I have a FrameLayout in which all the View should be in the center. Which FrameLayout attribute FrameLayout set the entire View to the center? So far, I expose all child elements

 android:layout_gravity="center" 

Is this the only way?

    2 answers 2

    If you need a FrameLayout , then just the way you do it now. Otherwise, you can use RelativeLayout , which supports the android:gravity 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> 
    • Thanks, I think that RelativeLayout "heavier" than FrameLayout because of attributes. But in terms of centering - to a point, gravity supported. - Flippy
     <FrameLayout android:id="@+id/CompassMap" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center"> // нужный параметр /////// </FrameLayout>