Android Rookie learning note 6----android Layout (one)

Source: Internet
Author: User
<span id="Label3"></p><p><p>The UI components of an Android app are inherited from the view class, and the view class represents a blank rectangular area. Common components such as textview, Button, edittext, etc. are inherited directly or indirectly from VIEW.</p></p><p><p>In addition, view has an important subclass of viewgroup, which can be used to contain multiple view components, which can itself be included as a view component by other viewgroup, thus building a very complex UI Interface.</p></p><p><p>Common layout managers such as framelayout, linearlayout, relativelayout and so on are directly inherited from Viewgroup.</p></p><p><p>In Android applications, activity is equivalent to a form in traditional desktop development, which is just created as a blank screen, so when you want to display the UI interface, you need to call the Setcontentview () method to pass in the view instance or layout resource that you want to display.</p></p><p><p>Such as:</p></p><p><p>To pass in a layout resource:</p></p><p><p>Setcontentview (r.layout.main);</p></p><p><p>To pass in a view instance:</p></p><p><p>TextView myTv = new TextView (this);</p></p><p><p>Setcontentview (myTv);</p></p><p><p>Mytv.settext ("hello, world");</p></p><p><p>Because Setcontentview () can only accept one view instance, to display a complex UI interface, you need to use ViewGroup to contain multiple view instances and then pass ViewGroup instances to SETCONTENTVIEW. ViewGroup is an abstract class that is generally used directly by its subclasses and is called the layout manager.</p></p><p><p>Android has two ways to write the UI interface, one in the XML layout resource file, the other is written directly in the code, such as the previous approach to a view instance is written directly in the code, which is the traditional approach to form programming. It is now recommended to write the UI interface in the XML layout resource file so that the application presentation layer can be separated from the logical layer, and the presentation layer can be modified without modifying the Code.</p></p><p><p>To write a complex UI interface, you need to master the layout manager that is commonly used in ANDROID. Mainly include:</p></p><p><p>Absolutelayout: Absolute Layout</p></p><p><p>Framelayout: Frame Layout</p></p><p><p>Linearlayout: Linear layout</p></p><p><p>Relativelayout: Relative layout</p></p><p><p>Tablelayout: Table Layout</p></p><p><p>Gridlayou: Grid Layout (new layout manager added by Android 4.0)</p></p><p><p><strong>1.LinearLayout</strong> <strong>Linear Layout</strong></p></p><p><p>The linear layout is where the view components are aligned in a linear alignment and can be arranged vertically or horizontally.</p></p><p><p>How to create a new layout resource file:</p></p><p><p>Right-click res/layout, then select New from the pop-up menu and select Android Xml file, to create a new LinearLayout layout file, Select LinearLayout as its root node.</p></p><p><p>The Linear_layout.xml code is as Follows:</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"><?</span></span><span style="color: #ff00ff;"><span style="color: #ff00ff;">XML version= "1.0" encoding= "utf-8"</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">?></span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">LinearLayout</span></span><span style="color: #ff0000;"><span style="color: #ff0000;">xmlns:android</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "http://schemas.android.com/apk/res/android"</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">android:orientation</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "vertical"</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">></span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "aaaaaa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> at</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "bbbbbb"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> to</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> *</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008080;"><span style="color: #008080;">Panax Notoginseng</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "cccccc"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "dddddd"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;">Wuyi</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></</span></span><span style="color: #800000;"><span style="color: #800000;">LinearLayout</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">></span></span></pre><p><p></p></p><p><p>The code in activity is as follows:</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">void</span> <span style="color: #000000;">onCreate (Bundle Savedinstancestate) {</span><span style="color: #008080;">2</span><span style="color: #008080;">3</span> <span style="color: #008000;">//</span> <span style="color: #008000;">TODO auto-generated Method Stub</span> <span style="color: #008080;">4</span> <span style="color: #008080;">5</span> <span style="color: #0000ff;">Super</span> <span style="color: #000000;">. OnCreate (savedinstancestate);</span> <span style="color: #008080;">6</span> <span style="color: #008080;">7</span> <span style="color: #000000;"> Setcontentview (r.layout.linear_layout);</span> <span style="color: #008080;">8</span> <span style="color: #008080;">9</span> }</pre></pre><p><p></p></p><p><p>Display Effect:</p></p><p><p></p></p><p><p>Several common Properties are:</p></p><p><p><strong>1</strong> <strong>) Orientation</strong> <strong>Properties</strong> : Sets the arrangement of the components in the linearlayout, either <strong>vertical</strong> or <strong>horizontal</strong> to either vertical or horizontal rows.</p></p><p><p>In the above code, if the orientation is set to Horizontal. The Display becomes:</p></p><p><p></p></p><p><p>Because only one row is displayed, and the width of the first button is full of the parent element, only the first button is Displayed.</p></p><p><p><strong>2</strong> <strong>) Layout_width</strong> <strong>Property</strong> : Sets the width of the component in the parent element, which can be <strong>wrap_content</strong>,<strong>match_parent</strong> , or <strong>fill_parent</strong>. Where wrap_content means that the width is able to wrap the contents of the component, fill_parent and match_parent mean the same meaning that the width is full of the parent element, and now the match_parent is used more often, and the fill_parent is seldom used.</p></p><p><p>If all the Button's layout_width are set to Wrap_content in the code above, the effect is as Follows:</p></p><p><p></p></p><p><p><strong>3</strong> <strong>) Layout_height</strong> <strong>Property</strong> : Sets the width of the component in the parent element, with a value of Layout_width.</p></p><p><p><strong>4</strong> <strong>) grativity</strong> <strong>Properties</strong> : Sets the alignment of components within the Container.</p></p><p><p>If you add a property in the LinearLayout node: android:gravity= "center_vertical"</p></p><p><p>The results are shown as Follows:</p></p><p><p></p></p><p><p>The value of this property can be: top, bottom, left, right, center, center_vertical, center_horizontal equivalent, or these values or (ascended or arithmetic |)</p></p><p><p>Such as: android:gravity= "bottom|right" display effect</p></p><p><p></p></p><p><p><strong>5</strong> <strong>) layout_gravity</strong> <strong>Property</strong> : The position of the current control at the parent Element.</p></p><p><p>If Layout_gravity is set to "center" in the aaaaaa button, the effect will be superimposed with the gravity attribute effect in the container that is linearlayout, as shown below:</p></p><p><p></p></p><p><p>is centered vertically, horizontally or on the left side of the BBBBBB</p></p><p><p><strong>6</strong> <strong>) Layout_weight</strong> <strong>Property</strong> : Sets the allocation weight for extra space in the parent element in the child Control.</p></p><p><p></p></p><p><p>At this point, if you set the Layout_weight property only in the AAAAAA button, you can set it to any value, and the custom setting is 1. The aaaaaa button will stretch to occupy the rest of the space, as shown below:</p></p><p><p></p></p><p><p>If the Layout_weight property is set in both AAAAAA and dddddd two buttons, and the first is set to 1 and the second is set to 2, the remaining space before the excess will be assigned to AAAAAA 1/3, to DDDDDD 2/3, which is the respective weight value/ The total weight value, that is, the proportion of the remaining space to be divided, is shown as Follows:</p></p><p><p></p></p><p><p><strong>7</strong> <strong>) WeightSum</strong> <strong>Property</strong> : Sets the total weight value of the remaining space in the container, which is a property in linearlayout, and Layout_weight is a property in each child control, and, if not set, defaults to the sum of Layout_weight property values for each child Control.</p></p><p><p>If the value of Layout_weight as above aaaaaa layout_weight value is 2 and the LinearLayout value in Weightsum is set to 6, there will still be half the remaining space. AAAAAA only the original remaining space of the 1/6,dddddd divided by 2/6, shown as Follows:</p></p><p><p></p></p><p><p><strong>8</strong> <strong>) Visibility</strong> <strong>Properties</strong> : Control whether the display, the value can be invisible, visible, gone. Visible indicates that invisible and gone do not appear, where invisible does not appear, but the control still exists, occupies space, and gone means that the control does not exist, and it does not occupy Space.</p></p><p><p>For example: CCCCCC Setting the visibility property to gone, as shown below:</p></p><p><p></p></p><p><p>If you change to Invisible:</p></p><p><p></p></p><p><p>LinearLayout setting Invisible:</p></p><p><p></p></p><p><p><strong>2.RelativeLayout</strong> <strong>: Relative Layout</strong></p></p><p><p>As the name implies, according to the relative position of each control layout, relative position, can be child control a relative to the position of the parent control, or child control a relative to applies control B Position.</p></p><p><p>Right-click res/layout, then select New from the pop-up menu and select Android Xml file, to create a new Relativelayout layout file, Select Relativelayout as its root node. The file name is Relative_layout.xml.</p></p><p><p>The code is as Follows:</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"><?</span></span><span style="color: #ff00ff;"><span style="color: #ff00ff;">XML version= "1.0" encoding= "utf-8"</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">?></span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Relativelayout</span></span><span style="color: #ff0000;"><span style="color: #ff0000;">xmlns:android</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "http://schemas.android.com/apk/res/android"</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "match_parent"</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">></span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:id</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@+id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">android:layout_centerinparent</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "true"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "aaaaaa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> at</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:id</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@+id/bb"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> to</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_torightof</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> *</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_aligntop</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008080;"><span style="color: #008080;">Panax Notoginseng</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "bbbbbb"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:id</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@+id/cc"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_toleftof</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;">Wuyi</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_alignbottom</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "cccccc"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> wu</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> about</span> <span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:id</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@+id/dd"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_above</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_alignleft</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "dddddd"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Button</span></span><span style="color: #008080;"><span style="color: #008080;"></span> about</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:id</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@+id/ee"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_width</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_height</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "wrap_content"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;">Bayi</span></span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_below</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:layout_alignleft</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "@id/aa"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #ff0000;"><span style="color: #ff0000;">Android:text</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "eeeeee"</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;">/></span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;"></</span></span><span style="color: #800000;"><span style="color: #800000;">Relativelayout</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">></span></span></pre><p><p></p></p><p><p>Modify Firstactivity in Setcontentview (r.layout.relative_layout);</p></p><p><p>Display Effect:</p></p><p><p></p></p><p><p>AAAAAA is centered in the parent container</p></p><p><p>The BBBBBB is displayed on the right side of the aaaaaa and aligned with the top of the AAAAAA</p></p><p><p>CCCCCCC is displayed on the left side of AAAAAA and aligned with the top of the AAAAAA</p></p><p><p>DDDDDD shown on AAAAAA and left aligned with AAAAAA</p></p><p><p>Eeeeee is shown below aaaaaa and left-aligned with AAAAAA</p></p><p><p>Primary Properties: Both the relative position of the parent and child, or the relative position of the child control</p></p><p><p>Android:layout_torightof on the right side of the specified control</p></p><p><p>Android:layout_toleftof on the left side of the specified control</p></p><p><p>Android:layout_above the top of the specified control</p></p><p><p>Android:layout_below the bottom of the specified control</p></p><p><p>Android:layout_alignbaseline horizontal alignment with the specified control</p></p><p><p>Android:layout_alignleft left-aligned with the specified control</p></p><p><p>Android:layout_alignright right-aligned with the specified control</p></p><p><p>Android:layout_aligntop aligns with the top of the specified control</p></p><p><p>Android:layout_alignbottom aligns with the bottom of the specified control</p></p><p><p>Android:layout_alignparentleft is left-aligned with the parent layout</p></p><p><p>Android:layout_alignparenttop is aligned with the top of the parent layout</p></p><p><p>Android:layout_alignparentright is right-aligned with the parent layout</p></p><p><p>Android:layout_alignparentbottom is aligned with the bottom of the parent layout</p></p><p><p>Android:layout_centervertical Center vertically in the parent layout</p></p><p><p>Android:layout_centerhorizontal Center horizontally in parent layout</p></p><p><p>Android:layout_centerinparent Center in parent layout</p></p><p><p></p></p><p><p>Android Rookie learning note 6----android Layout (one)</p></p></span>

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.