Android applications realize vertical and horizontal center layout with LinearLayout

Firstly, the centering under the LinearLayout layout is generally as follows: (Note: in the Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" attribute, if it is horizontally centered, it will occupy the full screen at least in width; if it is vertically centered, it will occupy the full screen in height)

To achieve vertical and horizontal centering, several basic parameters should be noted: 1. Android: orientation = "vertical" indicates that the elements under the layout are arranged vertically; 2、android:layout_ Gravity = "center_horizontal" indicates that the layout is horizontally centered in the parent layout. At this time, the parent layout must have Android: orientation = "vertical" attribute; 3、android:layout_ Gravity = "center_vertical" means that the layout is vertically centered in the parent layout. At this time, the parent layout must be set to Android: orientation = "horizontal" attribute (this attribute is the default), and the height of the parent layout should be set to Android: layout_ Height = "fill_parent" attribute; 4. Android: gravity = "center_horizontal" indicates that the elements under the layout are centered horizontally;

Linear layout vertically and horizontally centered layout file instance:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>