(1) Tablelayout:
can use
Android:stretchcolumns= "0,3" allows two columns on the left and right side of the don't pull to extend
For example:
<?xml version= "1.0" encoding= "Utf-8"? ><tablelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:id=" @+id/tablelayout1 "android:layout_width=" match_parent "android:layout_height=" Match_parent " android:background= "@drawable/loginbg" android:gravity= "center_vertical" android:stretchcolumns= "0,3" > < ;! --android:stretchcolumns= "0,3" the first and fourth columns are allowed to be stretched so that the user login form resides in the horizontal direction--<!--first row--<tablerow Android:id= "@+id/tablerow1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" > <textview/> <textview android:id= "@+id/textview1" android:layout_width = "Wrap_content" android:layout_height= "wrap_content" android:text= "User name:"/> <edittext Android:id= "@+id/edittext1" android:layout_width= "wrap_content" android:layout_height= "Wra P_content "ANDROID:MINWIdth= "200px" android:textsize= "24px"/> <textview/> </TableRow> <!--second line-- <tablerow android:id= "@+id/tablerow2" android:layout_width= "Wrap_content" Android:layout_heigh t= "Wrap_content" > <textview/> <textview android:id= "@+id/textview2" Android Oid:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "password" an Droid:textsize= "24px"/> <edittext android:id= "@+id/edittext2" android:layout_width= "WR Ap_content "android:layout_height=" wrap_content "android:inputtype=" Textpassword "Android : minwidth= "200px" android:textsize= "24px"/> <textview/> </TableRow> <tablerow Android:id= "@+id/tablerow2" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" > <textview /> <textview/> <button android:id= "@+id/button1" Android:layout_width= "W Rap_content "android:layout_height=" wrap_content "android:text=" Login "android:textsize=" 24p X "/> <textview/> </TableRow></TableLayout>
Relativelayout Content Center Solution:
Using LinearLayout to take advantage of the parent control's Gravity property is a good solution. However, the corresponding relativelayout has a gravity attribute, but if you use it, you will find that he is not effective.
Workaround: In the relativelayout subspace, use the following 3 attributes.
Android:layout_centervertical= "true"
Android:layout_centerhorizontal= "true"
Android:layout_centerinparent= "true"
Gravity is generally used for linearlayout will be very convenient.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android inside how to let the interface center