Android (java) Learning Note 93:android One of the detailed layouts: framelayout
Source: Internet
Author: User
<span id="Label3"></p><p><p>The framelayout is the simplest layout. All controls placed in the layout are stacked hierarchically in the upper-left corner of the Screen. The added control overrides the preceding Control.</p></p><p><p>In the Framelayout layout, it is meaningless to define the location-related properties of any Space. The controls are stacked automatically in the upper left corner and don't listen to your control at All.</p></p><p><p>Look at the following example:</p></p><p><p></p></p><p align="left"><p align="left"><?xml version= "1.0" encoding= "utf-8"?></p></p><p align="left"><p align="left"><framelayout xmlns:android= "http://schemas.android.com/apk/res/android"</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "fill_parent"</p></p><p align="left"><p align="left">></p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "50dip"</p></p><p align="left"><p align="left">Android:textcolor= "#ffffff"</p></p><p align="left"><p align="left">android:text= "first floor"/></p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "40dip"</p></p><p align="left"><p align="left">Android:textcolor= "#ffff00"</p></p><p align="left"><p align="left">android:text= "second floor"/></p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "30dip"</p></p><p align="left"><p align="left">Android:textcolor= "#ff00ff"</p></p><p align="left"><p align="left">android:text= "third floor"/></p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "20dip"</p></p><p align="left"><p align="left">Android:textcolor= "#00ffff"</p></p><p align="left"><p align="left">android:text= "fourth floor"/></p></p><p align="left"><p align="left"></FrameLayout></p></p><p align="left"><p align="left"></p></p><p><p>Effects such as: layoutpic001</p></p><p><p></p></p>Change 1<p><p>Let's try to change their position now. Change the first and second text boxes to a:</p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:id= "@+id/tv1"</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "50dip"</p></p><p align="left"><p align="left">Android:textcolor= "#ffffff"</p></p><p align="left"><p align="left">android:text= "first floor"/></p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:id= "@+id/tv2"</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "40dip"</p></p><p align="left"><p align="left">Android:textcolor= "#ffff00"</p></p><p align="left"><p align="left"><strong><em>android:layout_torightof= "@id/tv1"</em></strong></p></p><p align="left"><p align="left">android:text= "second floor"/></p></p><p><p>That is, let the second text box be placed to the right of the first text box. Let's look at the Effect. Did you see it? Still the same as the Same.</p></p>Change 2<p><p>Let's try the next android:gravity Property. Change the third text box to A:</p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:id= "@+id/tv3"</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "30dip"</p></p><p align="left"><p align="left">Android:textcolor= "#ff00ff"</p></p><p align="left"><p align="left"><strong> <em>android:gravity= "right"</em></strong></p></p><p><p>android:text= "third floor"/></p></p><p><p>See how it works? Oh, my God! Unexpectedly not covered, but staggered!!!</p></p><p><p>layoutpic002</p></p><p><p></p></p><p><p>First of all, let's not make a fuss. This phenomenon does not indicate that Framelayout is Invalid. The Gravity property is the format that controls the inner text of the Control. And what do we look at the wide properties of our controls? Is "fill_parent", that is to say, the width of our text box is the width of the Screen. Then <strong><em>the android:gravity= "right"</em></strong> text is on the left, and the text box itself is stacked on top of it. Do not believe, we will change:</p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:id= "@+id/tv3"</p></p><p align="left"><p align="left">Android:layout_width= "wrap_content"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "30dip"</p></p><p align="left"><p align="left">Android:textcolor= "#ff00ff"</p></p><p align="left"><p align="left"><strong> <em>android:gravity= "right"</em></strong></p></p><p><p>android:text= "third floor"/></p></p><p><p>We make the width of the third text box adaptive, that is, the full text is guaranteed to be displayed. What about the effect at this time? Did you hit the back? Hahaha.</p></p>Change 3<p><p>Let's try the "android:layout_centervertical" property again. Change the fourth text box to:</p></p><p align="left"><p align="left"><textview</p></p><p align="left"><p align="left">Android:id= "@+id/tv4"</p></p><p align="left"><p align="left">Android:layout_width= "fill_parent"</p></p><p align="left"><p align="left">android:layout_height= "wrap_content"</p></p><p align="left"><p align="left">Android:textsize= "20dip"</p></p><p align="left"><p align="left">Android:textcolor= "#00ffff"</p></p><p align="left"><p align="left">Android:layout_centervertical= "true"</p></p><p><p>android:text= "fourth floor"/></p></p><p><p>What's The effect? It doesn't have any effect!</p></p><p><p></p></p><p><p>To summarize, after the 3 experiments above, we know that Framelayout cannot control the location of his child controls at All. All the controls are on top left to Them. however, the control itself can control its own internal Layout. So the use of transparency, but also can do some simple functions. For example, Four corners of the screen display some text (is the display text, cannot place the control). Because each layer covers the next layer, if you use a transparent background, the next layer will not be covered by the Background.</p></p><p><p>What is a transparent background? This one...... It's a long Story. Steal a lazy, next time write a transparent processing.</p></p><p><p>Does anyone ask, what is the use of such a simple layout? I think there is a value to its existence.</p></p><p><p>When you need to write a view, you have completed your logic in view (such as the game ^_^), then the view only needs a container placement, you can use the Framelayout. Although it is possible to use other layouts, the simplest is not to save the system Resources.</p></p><p><p></p></p><p class="prev_article"><p class="prev_article"></p></p><p><p> Android (java) Learning Note 93:android One of the layouts: framelayout </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