Android inside how to let the interface center

Source: Internet
Author: User

(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" > &lt ;!         --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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.