The linear layout of the Android Layout--linearlayout
Source: Internet
Author: User
<span id="Label3"></p><p><p>This article details the various XML attributes of a linear Layout.</p></p><p><p> <strong>XML properties</strong></p></p><pre><pre><span style="font-family: 宋体; font-size: 14px;"><?xml version= "1.0" encoding= "utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "<span style="color: #000000;"> android:layout_width</span>=" match_parent "<span style="color: #000000;"> android:layout_height</span>=" match_parent " <span style="color: #000000;"> android:orientation</span>= "vertical" ></LinearLayout></span></pre></pre><p><p>①<strong>android:layout_width</strong>----> Set the width of this layout, there are three modes:</p></p><p><p> <em><strong>fill_parent</strong></em>: Full screen (obsolete, replaced with the following Match_parent)</p></p><p><p> <em><strong>match_parent</strong></em>: Full Screen (recommended)</p></p><p><p> <em><strong>wrap_parent</strong></em>: Contains components, meaning how large your component is, and how much space it takes.</p></p><p><p>②<strong>android:layout_height</strong>----> Set the height of this layout, the pattern is as above;</p></p><p><p>③<strong>android:orientation</strong>----> This property sets the way this linear layout has two parameters:</p></p><p><p> <em><strong>vertical</strong></em>: Vertical layout: that is, child controls are in the upper and lower positions of child controls, such as</p></p><pre><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"><span style="color: #000000;">Android:layout_width</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">android:orientation</span></span>= "vertical" >//vertical layout is selected here <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "match_parent"//width Full Screen<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"//height contains components<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "firstbutton"<span style="color: #000000;"><span style="color: #000000;">Android:id</span></span>= "@+id/button"/> <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "secondbutton"<span style="color: #000000;"><span style="color: #000000;">Android:id</span></span>= "@+id/button2"/></linearlayout></pre><p><p>Show Results:</p></p><p><p></p></p><p><p> <em><strong>Horizontal</strong></em>: Horizontal layout: that is, the child controls are in the left and right positions of the child Controls. For example:</p></p><pre><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"><span style="color: #000000;">Android:layout_width</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">android:orientation</span></span>= "horizontal" >//set Here for horizontal layout, <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "wrap_content"//width contains components<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "match_parent"//here Sets the height of the button control to fill the screen<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "firstbutton"<span style="color: #000000;"><span style="color: #000000;">Android:id</span></span>= "@+id/button"/> <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "secondbutton"<span style="color: #000000;"><span style="color: #000000;">Android:id</span></span>= "@+id/button2"/></linearlayout></pre><p><p>Show Results:</p></p><p><p></p></p><p><p>④<strong>android:baselinealigned</strong>----> If the child controls in this layout are aligned in the baseline, it is actually set on a line that is not on one of the lines, and he has only two parameters, true and False</p></p><p><p> <strong> <em>false</em>:</strong> If set to false, then the content inside of him is not aligned.</p></p><p><p> <em><strong>true</strong></em> <strong>:</strong> If set to true, then ALIGN. For example:</p></p><pre><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"><span style="color: #000000;">Android:layout_width</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">android:baselinealigned</span></span>= "false"//set here to False<span style="color: #000000;"><span style="color: #000000;">android:orientation</span></span>= "horizontal" > <<span style="color: #000000;"><span style="color: #000000;">TextView android:layout_width</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "hello"<span style="color: #000000;"><span style="color: #000000;">android:textsize</span></span>= "24sp"/> <<span style="color: #000000;"><span style="color: #000000;">TextView android:layout_width</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "world"/> <<span style="color: #000000;"><span style="color: #000000;">TextView android:layout_width</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "hello world"<span style="color: #000000;"><span style="color: #000000;">android:textsize</span></span>= "45sp"/></linearlayout></pre><p><p>Show Results:</p></p><p><p></p></p><p><p>When set to True:</p></p><p><p></p></p><p><p>Results at a glance.</p></p><p><p>⑤<strong>android:gravity</strong>: Specifies the location of the child controls inside the layout, a few common parameters that can accept two parameters in the middle with "|" Separate</p></p><p><p> <em><strong></strong></em>Center: The control is in the central position of the Layout.</p></p><p><p> <em><strong></strong></em>Left: The control is located on the leftmost side of the Layout.</p></p><p><p> <em><strong></strong></em>right: The control is on the left side of the Layout.</p></p><p><p> <em><strong>center|left</strong></em>: The control is positioned in the left position of the Layout. (can also use center_vertical, and this same Effect)</p></p><p><p>The properties given by the Official:</p></p><p><p></p></p><p><p>Everyone can see Righteousness. Example:<span style="line-height: 1.5;"> </span></p></p><pre><pre><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"> android:layout_width</span>= " Match_parent "<span style="color: #000000;"> android:layout_height</span>=" match_parent "<span style="color: #000000;"> android:gravity</span>=" center|left " <span style="color: #000000;"> android:orientation</span>= "horizontal" > <<span style="color: #000000;">TextView android:layout_width</span>= "wrap_ Content "<span style="color: #000000;"> android:layout_height</span>=" wrap_content "<span style="color: #000000;"> android:text</span>=" Hello " <span style="color: #000000;"> Android:textsize</span>= "24sp" /></linearlayout></pre></pre><p><p>The results shown are:</p></p><p><p></p></p><p><p>⑥<strong>android:layout_gravity</strong>: Refers to the position of this child control in the Layout. Parameters Above:</p></p><pre><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"><span style="color: #000000;">Android:layout_width</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">android:orientation</span></span>= "vertical" > <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "hello"<span style="color: #000000;"><span style="color: #000000;">android:gravity</span></span>= "left"<span style="color: #000000;"><span style="color: #000000;">android:textsize</span></span>= "24sp"/> <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "hello"<span style="color: #000000;"><span style="color: #000000;">android:textsize</span></span>= "24sp"<span style="color: #000000;"><span style="color: #000000;">android:layout_gravity</span></span>= "center"/></linearlayout></pre><p><p>Show Results:</p></p><p><p></p></p><p><p>⑦<strong>Android:divider</strong>: Draws a split line between subassemblies, which can be either a picture or an XML shape tag, a picture or shape located under drawable</p></p><p><p> <strong>android:showdividers</strong>: There are four ways to display split lines:</p></p><p><p> <em><strong>begging</strong></em>: Add on top of the whole</p></p><p><p> <em><strong>Middle</strong></em>: add between each component</p></p><p><p> <em><strong>End</strong></em>: Add to the bottom of the whole</p></p><p><p> <em><strong>None</strong></em>: Not displayed</p></p><p><p>For example:</p></p><pre><pre><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"> android:layout_width</span>= " Match_parent "<span style="color: #000000;"> android:layout_height</span>=" match_parent "<span style="color: #000000;"> android:divider</span>=" @drawable/shapee "//the Shapee referenced here is an XML file, the code below <span style="color: #000000;"> android:showdividers</span>=" Middle "//the method shown here is to add <span style="color: #000000;">android:o between each component Rientation</span>= "vertical" ></pre></pre><p><p>Shapee.xml file</p></p><pre><pre><?xml version= "1.0" encoding= "utf-8"? ><shape xmlns:android= "http://schemas.android.com/apk/res/android" > <solid android:color= "#00ff00"/>//this property specifies the color <size android:height= "5px"/> Height of Split Line </shape></pre></pre><p><p>The effect is as Follows:</p></p><p><p></p></p><p><p>⑧<strong>android:weightsum</strong>: Setting the sum of weight in a child control is actually the ratio of controlling the child control to the screen or other child controls, the personal feeling this is more important, for the layout has a good effect.</p></p><p><p>For example, code:</p></p><pre><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"><span style="color: #000000;">Android:layout_width</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "match_parent"<span style="color: #000000;"><span style="color: #000000;">android:orientation</span></span>= "horizontal"//layout set to horizontal layout<span style="color: #000000;"><span style="color: #000000;">Android:weightsum</span></span>= "1"//set the weight sum of the child controls to 1 > <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "0dp"//this is set to 0 for good calculation, The calculation formula is described below<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:layout_weight</span></span>= "0.5"//here Set weight (weighted Value) is 0.5, that is, take up half of the Line.<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "hello"<span style="color: #000000;"><span style="color: #000000;">android:textsize</span></span>= "24sp"/> <<span style="color: #000000;"><span style="color: #000000;">Button android:layout_width</span></span>= "0dp"<span style="color: #000000;"><span style="color: #000000;">Android:layout_height</span></span>= "wrap_content"<span style="color: #000000;"><span style="color: #000000;">Android:layout_weight</span></span>= "0.4"//here is 0.4, is 40%, and 1-0.5-0.4=0.1 is blank<span style="color: #000000;"><span style="color: #000000;">Android:text</span></span>= "hello"<span style="color: #000000;"><span style="color: #000000;">android:textsize</span></span>= "24sp"/></linearlayout></pre><p><p>Show Results:</p></p><p><p></p></p><p><p>Calculation Formula: The width of the button in this instance is calculated: { <strong>Button's width value +button The weight* parent control width ( <em>here is match_content,</em> </strong></p></p><p><p><em><strong>If the parent control is 200dp,</strong></em> <strong style="line-height: 1.5;"> <em>So here is</em>the value of the Weightsum</strong> <span style="line-height: 1.5;"> }</span></p></p><p><p> </p></p><p><p></p></p><p><p> </p></p><p><p>The linear layout of the Android Layout--linearlayout</p></p></span>
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