Original article, if reproduced, please indicate the source: http://blog.csdn.net/yihui823/article/details/6702273
Framelayout is the simplest layout. All controls placed in the layout are stacked in the upper left corner of the screen by hierarchy. The added control overwrites the previous one.
In the framelayout layout, defining the location-related attributes of any space is meaningless. The control is automatically stacked in the upper left corner, and does not listen to your control.
See the following example:
<? 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 = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "50dip"
Android: textcolor = "# ffffff"
Android: text = "first layer"/>
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "40dip"
Android: textcolor = "# FFFF00"
Android: text = "Layer 2"/>
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "30dip"
Android: textcolor = "# ff00ff"
Android: text = "Layer 3"/>
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "20dip"
Android: textcolor = "#00 FFFF"
Android: text = "Layer 4"/>
</Framelayout>
Effect: layoutpic001
Change 1
Now let's try to change their location. Change the first and second text boxes:
<Textview
Android: Id = "@ + ID/TV1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "50dip"
Android: textcolor = "# ffffff"
Android: text = "first layer"/>
<Textview
Android: Id = "@ + ID/TV2"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "40dip"
Android: textcolor = "# FFFF00"
Android: layout_torightof = "@ ID/TV1"
Android: text = "Layer 2"/>
That is to say, place the second text box on the right of the first text box. Let's take a look at the effect. Did you see it? It remains the same.
Change 2
Let's try the Android: gravity attribute. Change the third text box:
<Textview
Android: Id = "@ + ID/TV3"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "30dip"
Android: textcolor = "# ff00ff"
Android: gravity = "right"
Android: text = "Layer 3"/>
What is the result? Oh, my God! I did not overwrite it, but staggered it !!!
Layoutpic002
First, we should not make a fuss. This does not indicate that framelayout is invalid. The gravity attribute controls the format of the internal text of the control. What is the property of the width of our control? Is "fill_parent", that is, the width of the text box is the width of the screen. SoAndroid: gravity = "right"The text is right-aligned, and the text box itself is stacked on the top left. Don't believe it. Let's change it again:
<Textview
Android: Id = "@ + ID/TV3"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textsize = "30dip"
Android: textcolor = "# ff00ff"
Android: gravity = "right"
Android: text = "Layer 3"/>
We make the width of the third text box adaptive, that is, to ensure that all text is displayed. What is the result at this time? Is it true? Hahaha.
Change 3
Let's try the "Android: layout_centervertical" attribute again. Change the fourth text box:
<Textview
Android: Id = "@ + ID/TV4"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textsize = "20dip"
Android: textcolor = "#00 FFFF"
Android: layout_centervertical = "true"
Android: text = "Layer 4"/>
What is the effect? No effect!
To sum up, after the above three experiments, we know that framelayout cannot control the position of its sub-control. All controls are on the top left. However, the control itself can control its internal layout. Therefore, the use of transparency can also complete some simple functions. For example, some text is displayed at each of the four corners of the screen (it is a display text and cannot be placed with controls ). When each layer covers the next layer, if a transparent background is used, the next layer will not be overwritten.
What is a transparent background? This ...... Let's talk about it. I am a little lazy. Next time I write transparent processing.
Will someone ask, what is the use of such a simple layout? I think it still has the value of its existence.
When you need to write a view by yourself, you have completed your logic in the view (for example, in the game pai_^), then this view only needs to be placed in a container, you can use framelayout. Although other la s can also be used, the simplest method is not to save system resources.