-In view of the examples of center-centered tasks, I would like to sum up my understanding here.
-Center: The Center is divided into two different layout methods! They are linearlayout andRelative
Layout.
-Center in the linearlayout layout: directly paste the source code
Note: In the Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" attribute, if the horizontal center is at least full screen on the width, if the vertical center is at the height, full screen is taken on the height.
<Linearlayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: gravity = "center | center_horizontal | center_vertical"> // The preceding gravity attribute parameter: Center, center_horizontal is horizontally centered and center_vertical is vertical centered <button Android: Id = "@ + ID/binding_button" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "associate a new account"/> </linearlayout>
-Then, we will talk aboutRelative
Center in layout:
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <button Android: Id = "@ + ID/btngal" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: gravity = "center_horizontal" Android: textsize = "20sp" Android: layout_alignparentbottom = "true" Android: layout_centerhorizontal = "true" Android: text = "back to main interface"/> </relativelayout>
Simple Description
Android: gravity = "center_vertical": vertical center alignment
Android: gravity = "bottom": placed at the bottom of the container
Android: gravity = "center": placed in the center of the container