<span id="Label3"></p><span style="font-size:12px"><span style="font-size:12px">Layout (commonlayout,adapter Layout)</span></span><p><br>Commonlayout General Layout<br>Layout view (viewgroup in Android Ui)<br><br>Common Layout General Layouts<br>padding inner margin margin scrollbars scroll bar<br>1) relativelayout (relative Layout)<br>Characteristics:<br>1. Each control can use other controls as a reference point to determine its own size or position<br>2. You must first identify 1 controls that do not use other controls as reference points, but can directly determine their size and position<br>3. When the control is not using a reference point control, the default is to use the root layout as the reference point, and left-aligned, top-aligned<br>4. Sub-layout controls in relative layouts can overlap<br>Properties: unique properties: align Series--set the control to align to the left and right of the corresponding control<br>No<br>To series--set the control to the top and bottom of the corresponding control<br>Properties of the child control relative to the Layout:<br>1. Android:layout_alignparentleft-align the left edge of the parent control, with a value of true or False<br>2. Android:layout_alignparentright-align to the right edge of the parent control, same value as above<br>3. Android:layout_alignparenttop-align the top edge of the parent control, with the same value as above<br>4. android:layout_alignparentbottom, align the bottom edge of the parent control, and take the same value as above<br>5. android:layout_centerhorizontal, centered horizontally in the parent control, with the same value as above<br>6. android:layout_centervertical-in Parent Control scope content Vertically Center aligned, same value as above<br>7. Android:layout_centerinparent Center aligns horizontally and vertically within the scope of the parent control, with the same value as above<br>8. android:layout_aligntop, align vertically with the top of one of the other controls, and take the value to the ID of the other control<br>9. android:layout_alignbottom, align with the bottom of one of the other controls in the vertical direction, and take the value IBID.<br>8. android:layout_alignleft, align horizontally with the left side of one of the other controls, and take the same value as above<br>9. android:layout_alignright, align horizontally with the right side of one of the other controls, and take the same value as above<br>Android:layout_toleftof. set control to the left of another control in the horizontal direction, with the value of the other Control's ID<br>Android:layout_torightof. set the position of the control in the horizontal direction on the right side of one of the other controls, with the same value as above<br>Android:layout_above. set control in the vertical position above some other control, take value as above<br>android:layout_below, setting controls in the vertical position below one of the other controls, take the same value as above<br>Ps:<br>1. When other controls are used as reference points, the other control must be a sibling (having the same direct parent Control) as the control<br>2. No reference to each other<br>1.RelativeLayout (relative Layout)<br><br>Each component that is defined is laid out relative to other components (<br>Each component has a relative position), which is typically used with more complex<br>Layout Page.<br><br>Description<br>1) all layout objects are used in the activity, either directly<br>The new is either defined in the XML file of the Res/layout directory.<br>2) when working with all layout objects, you need to focus on the layout<br>and Common Properties.<br><br>2) LinearLayout (linear Layout)<br>Characteristics:<br>1. Controls for direct child layout are arranged in the order of the Code<br>2. Controls for direct child layouts can be scaled by scale<br>Properties: Special properties: weight to 0dp, set weight to allocate space proportionally<br>Orientation--set The internal space to be vertically (horizontally) arranged<br>Android:orientation layout direction, with a value of vertical or horizontal, which represents the control of the child layout in the vertical direction (top to bottom), which represents the horizontal orientation of the control of the child layout (left to Right)<br>Ps: a control of the direct child layout of a linear layout can be configured with the following properties:<br>android:layout_weight-weighted/proportional, integer value<br>android:layout_gravity, with a value of left, right, top, bottom, center, or a combination of 2 conflicting values, such as Top|left<br><br>3) GridLayout (grid Layout)<br>android:layout_row= "0" means starting from the first line,<br>android:layout_column= "0" means starting from the first column<br>Column-to-column<br>RowSpan---cross-line<br>4) framelayout (frame Layout)<br>5) absolutelayout Absolute Layout<br>Absolutelayout the absolute layout as if the div specified the absolute property, specifying the position of the element with x, y coordinates!<br>6) ...<br>2.Adapter Layout<br>1) ListView (list View)<br>2) GridView (grid View)<br>3) Spinner (drop-down List)<br>4) Viewpager (view Paging)<br>5) .....</p><p><p><br></p></p><p><p><br>Common Layout Optimization<br><br>1. Optimize the inheritance system (reduce Hierarchy)<br>Example: Merge with merge tab for same layout<br><merge/> tags play a very important role in the structure optimization of the ui, which can prune unnecessary layers and optimize the Ui. <merge/> More is used to replace framelayout or when one layout contains another,<merge/> the label eliminates the extra view group in the view Hierarchy. For example, your main layout file is a vertical layout that introduces a vertical layout of include, which is meaningless if the linearlayout used by the include layout makes sense, and instead slows down your UI Performance. You can use <merge/> tag optimization at this Point.<br>Meger the effect shown in emulator after running the program is the same, but the UI structure viewed through Hierarchyviewer is changed, and the redundant layout nodes are merged together. Or it can be understood that the subset of the merge tag is added directly to the Activity's layout and node (note here: all activity views have a framelayout root node). If you create a layout that does not use framlayout as the root node (instead of defining root tags such as linerlayout), You cannot use the above example to optimize the UI structure by using Merge.<br>In addition to the above example, Meger has another usage, and when an include or viewstub tag is imported from an external XML structure, the imported XML can be represented as a root node in the Merge. This way, when embedded in the parent structure, it is good to dissolve the subset it contains into the parent structure without the redundant nodes.<br><merge/> tags are extremely useful. However it has also the following two restrictions:<br>1.<merge/> can only be used as the root tag of an XML layout<br>2 when the XML layout that needs to be expanded is itself composed of the merge as the root Node. (when inflate a layout file that starts with <merge/>), you must specify a parent viewgroup, and you must set Attachtoroot to True (see inflate (int, Android.view.ViewGroup (Boolean) method).<br><br></p></p><p><p><br></p></p><p>2. Reusing layout objects (include Tags)<br>Example: importing a shared layout with an include tag<br>The Relativelayout attribute cannot be set within the include tag, such as android:layout_alignparentbottom, because it does not work<br>After setting the id attribute in the Include tag (android:id), the id attribute in its referenced layout layouts does not work, and it is suspected that the layout outer layer of its reference is wrapped in an include tag<br>Or a property ID that overrides it.<br>Why if you do not have an include tag, all layout code is written in an XML file, and the interface appears redundant and poorly readable. And when the interface is loaded in order, the previous layout cannot<br>Call the layout ID that follows it. With include, you can refer to the Layout ID property of the include in an include<br>A layout can contain two identical include tags, which can be resolved using the following method (reference):<br>1. View bookmarks_container_2 = Findviewbyid (r.id.bookmarks_favourite);<br>2.<br>3. Bookmarks_container_2.findviewbyid (r.id.bookmarks_list);<br>3. Implementing deferred loading of objects (with Viewstub)<br>The biggest advantage of the <viewstub/> tag is that it does not load when you need it, and it doesn't affect performance when the UI is Initialized. A variety of infrequently used layouts like Progress bars, display error messages, and so on can use <viewstub/> tags to reduce memory usage and speed rendering. <viewstub/> is an invisible, 0-size view.<br>Some features of viewstub:<br>1. Viewstub can only be inflate once, and then viewstub objects will be Empty. According to the sentence, a viewstub specified by the layout is inflate, it will not be enough to control it through the viewstub.<br>2. Viewstub can only be used to inflate a layout file, not a specific view, of course, you can also write the view in a layout file.<br>Based on the above characteristics, the use of viewstub can be considered as Follows:<br>1. During the run of the program, a layout will not change after inflate, unless it is restarted.<br>Because viewstub can only be inflate once and then be empty, you cannot expect to use Viewstub to control the layout later. So when you need to show and hide a layout more than once at run time, viewstub can't. You can only use the visibility of the view to control it.<br>2. You want to control what is displayed and hidden is a layout file, not a view.<br>Because the ID of a layout file can only be set to viewstub, it cannot be controlled for a view.<br>so, if you want to control the display and concealment of a view (such as button or textview), or if you want to show and hide a layout or view at run time, you can only use the visibility of the view to control it.<br>When you want to load a layout, you can use one of the following methods:<br>1. ((viewstub) Findviewbyid (r.id.stub_import)). setvisibility (view.visible);<br>2.//or<br>3. View importpanel = ((viewstub) Findviewbyid (r.id.stub_import)). Inflate ();</p><p><p>Android Layout Learning Notes</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