How to center a View inside of an Android Layout?

后端 未结 10 1431
深忆病人
深忆病人 2020-12-07 18:18

I want to put a layout in the center of the screen.

相关标签:
10条回答
  • 2020-12-07 19:01

    Step #1: Wrap whatever it is you want centered on the screen in a full-screen RelativeLayout.

    Step #2: Give that child view (the one, which you want centered inside the RelativeLayout) the android:layout_centerInParent="true" attribute.

    0 讨论(0)
  • 2020-12-07 19:03

    Add android:layout_centerInParent="true" to element which you want to center in the RelativeLayout

    0 讨论(0)
  • 2020-12-07 19:06

    You can apply a centering to any View, including a Layout, by using the XML attribute android:layout_gravity". You probably want to give it the value "center".

    You can find a reference of possible values for this option here: http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_gravity

    0 讨论(0)
  • 2020-12-07 19:12

    I use android:layout_centerInParent="true" and it worked

    0 讨论(0)
提交回复
热议问题