Problem Description:
How to center the button horizontally vertically and always occupy half the screen width
The effect is as follows:
Vertical screen:
Horizontal screen:
Solution:
Using a linear layout, specifies that the total weight of the linear layout (WeightSum) is 1, and the weight of the specified button is half that of 0.5
The layout code is as follows:
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:background= "#FFFFFF"android:gravity= "Center"android:orientation= "Horizontal"Android:weightsum= "1"> <ButtonAndroid:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "0.5"Android:text= "click me"/></LinearLayout>
Android Development-How to make the button horizontal vertically and always occupy half the screen width