Talking about Android layout

Source: Internet
Author: User

In the previous blog, the small series introduced the Android Aurora push and how to implement a small demo login, for the XML Layout page, pendulum control this piece of content, small series is not very skilled, today's small series mainly simple summary of the layout in Android, The small partners who have studied Android know that there are five commonly used layouts in Android, as shown in:

Then, the small part of the detailed introduction of these several layouts, small series is a beginner, but also please all the small partners to advise OH. First, let's look at:

The first linearlayout---linear layout, the linear layout is one of the most commonly used layouts in the development of Android projects, where there are two types of linear layouts, vertical and horizontal, when vertical layout, each row has only one element, and multiple elements are vertically down Horizontal layout, there is only one row, and each element is arranged to the right. Let's look at a concrete example where the code looks like this:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical "        > <linearlayout android:layout_width= "fill_parent" android:layout_height= "Fill_parent" android:layout_weight= "1" android:orientation= "horizontal" > <textview android:text= "Blue" a Ndroid:gravity= "Center_horizontal" android:background= "#52C8FA" android:layout_width= "Wrap_content" a        ndroid:layout_height= "Fill_parent" android:layout_weight= "1"/> <textview android:text= "Yellow"        Android:gravity= "Center_horizontal" android:background= "#FFFF00" android:layout_width= "Wrap_content"        android:layout_height= "Fill_parent" android:layout_weight= "1"/> <textview android:text= "Pink" Android:gravity= "Center_horizOntal "android:background=" #F60C88 "android:layout_width=" wrap_content "android:layout_height=" fill_p Arent "android:layout_weight=" 1 "/> <textview android:text=" purple "android:gravity=" Center_ Horizontal "android:background=" #722694 "android:layout_width=" wrap_content "android:layout_height=" f Ill_parent "android:layout_weight=" 1 "/></linearlayout> <linearlayout android:orientation = "vertical" android:layout_width= "fill_parent" android:layout_height= "Fill_parent" Android:layout_ weight= "1" > <textview android:text= "green" android:textsize= "15pt" Android:background = "#39E18A" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:layout_ weight= "1"/> <textview android:text= "Pink" android:textsize= "15pt" android:background= "# F60c88 "Android:Layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1"/> & Lt TextView android:text= "Yellow" android:textsize= "15pt" android:background= "#FFFF00" Androi D:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1"/> &L T TextView android:text= "Blue" android:textsize= "15pt" android:background= "#52C8FA" Android:                     Layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1"/> </LinearLayout> </LinearLayout>
the effect is as follows:

The second framelayout---frame layout, where the frame layout starts from the upper-left corner (0,0) coordinates of the screen, multiple components are stacked, the first added component is placed at the bottom, and the view that is added to the frame is displayed at the top. The previous layer overrides the next layer of control, and the code looks like this:

<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent ">        <textview        android:layout_width= "300DP"         android:layout_height= "300DP"         android:background= "#52C8FA"/>     <textview            android:layout_width= "260DP"           android:layout_height= "260DP"           android:background= "# FFFF00 "/>     <textview            android:layout_width=" 220DP "           android:layout_height=" 220DP           " android:background= "#F60C88"/> </FrameLayout>  
the effect of the operation is as follows:

The third tablelayout---table layout, which is a viewgroup to display its child view elements in a table, where rows and columns identify the location of a view, and each tablelayout has a table row TableRow. TableRow can define each element in detail. Each layout has its own appropriate way, and the five layout elements can be nested within each other, and the code looks like this:

<?xml version= "1.0" encoding= "Utf-8"? ><tablelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent ">        <tablerow >         <button             android:text= "et"             android:background= "#52C8FA"/>         <button             android:text = "One"             android:background= "#FFFF00"/>         <button             android:text= "android:background="             # F60c88 "/>     </TableRow>     <TableRow>         <button             android:text="             android: background= "#722694"/>         <button             android:layout_span= "2"             android:text= "thing!"             android:background= "#39E18A"/>     </TableRow> </TableLayout>       

The effect is as follows:

The fourth relativelayout---relative layout, relative layout is based on the relative position between components layout, such as on the left side of a component, right, above and below, relative layout can be understood as an element as a reference, to locate the layout method, the specific code is as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" wrap_content "android:padding=" 10px "&G     T <textview android:id= "@+id/tev1" android:layout_width= "Wrap_content" android:layout_height = "Wrap_content" android:layout_marginbottom= "30DP" android:text= "Please enter the password, there will be surprise oh ' (*∩_∩*):"/> <ed Ittext android:id= "@+id/tx1" android:layout_width= "match_parent" android:layout_height= "Wrap_conte NT "android:layout_below=" @id/tev1 "/> <button android:id=" @+id/btn1 "Android:layout_hei ght= "Wrap_content" android:layout_width= "wrap_content" android:layout_below= "@id/tx1" Android:layo Ut_alignparentright= "true" android:text= "OK" android:background= "#FFFF00"/> <button Android       Oid:id= "@+id/btn2"  android:layout_height= "Wrap_content" android:layout_width= "wrap_content" android:layout_below= "@id/tx1" android:layout_toleftof= "@id/btn1" android:layout_marginright= "30DP" android:text= "Cancel" and  roid:background= "#FFFF00"/> </RelativeLayout>
the effect is as follows:


The fifth Absolutelayout---absolute layout, and the absolute layout determines the location of the component by specifying the exact x, y coordinates of the subassembly, indicating that the class has expired in the ANDROID2.0 API documentation. can use Framelayout or relativelayout to replace, small series is not to carry out the relevant introduction, the need for a small partner can move their own cute little hand, in the network of the world in search of Oh ' (*∩_∩*)!

Small Series of words: The blog, the small part of the main simple introduction of the common Android layout, looking at a code to run a successful, small part of the heart is very happy, in order to celebrate, this evening do not eat yellow stewed chicken, from the beginning of closed development projects to now, small series of daily eat yellow stewed chicken, This life do not want to eat, although these are not worth mentioning to Daniel, but it is because of this step and a small progress, small series will grow stronger, more beautiful.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talking about Android layout

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.