Objective
Write down some of the understanding of the layout today, including the inheritance of the properties of the control, the relationship between the control and the properties of the container, and the use of the properties of the various classes.
Types of properties for controls
In general, when we assign a property to a control, we generally have a type of property, a property that begins with Layout_, a property that does not start with Layout_, and is described below as an example of TextView, as follows
1 <Relativelayout2 Android:layout_width= "Match_parent"3 Android:layout_height= "Match_parent" >4 5 <TextView6 Android:layout_width= "Wrap_content"7 Android:layout_height= "Wrap_content"8 Android:text= "Hello_world" />9 Ten </Relativelayout>
I set three properties Layout_width, Layout_height, and text for TextView, and I can see that the Layout_width and Layout_height properties in these three properties are Layout_ Beginning and text does not start with Layout_.
Attributes that begin with Layout_ are inherited from the container, which in this case is inherited from the relativelayout, and TextView itself does not have this property. The text is a property owned by TextView itself.
To illustrate that the layout property is a container property, I have made the following example, placing the TextView in Relativelayout and LinearLayout, and then setting the Layout_centerinparent property on the TextView, All of this property is selected because this property is relativelayout all and linearlayout not, the experiment code is as follows
1 <Relativelayout2 Android:layout_width= "Wrap_content"3 Android:layout_height= "Wrap_content" >4 5 <TextView6 Android:layout_width= "Wrap_content"7 Android:layout_height= "Wrap_content"8 android:layout_centerinparent= "true"9 Android:text= "Hello_world" />Ten </Relativelayout> One A <LinearLayout - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" > the - <TextView - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" + android:layout_centerinparent= "true" - Android:text= "Hello world2" /> + </LinearLayout>
As shown above, the editor prompts "Invalid layout param in a linearlayout:layout_centerinparent" as follows
Through this experiment, it can be concluded that the properties at the beginning of layout are not owned by TextView, but rather the properties of the layout in the inherited container, and then, by the same conclusion, the properties of the control can be divided into its own properties and the layout properties in the container. The following is a detailed analysis of subordinates through TextView and various layout containers.
LinearLayout and TextView
This section mainly introduces the properties of the next LinearLayout and TextView, first to look at the properties of TextView, and the property inheritance relationship,
The following properties are owned by the TextView itself
| XML Attributes |
| Attribute Name |
| Android:autolink |
| Android:autotext |
| Android:buffertype |
| Android:capitalize |
| Android:cursorvisible |
| Android:digits |
| Android:drawablebottom |
| Android:drawableend |
| Android:drawableleft |
| Android:drawablepadding |
| Android:drawableright |
| Android:drawablestart |
| Android:drawabletop |
| Android:editable |
| Android:editorextras |
| Android:ellipsize |
| Android:ems |
| Android:fontfamily |
| Android:freezestext |
| Android:gravity |
| Android:height |
| Android:hint |
| Android:imeactionid |
| Android:imeactionlabel |
| Android:imeoptions |
| Android:includefontpadding |
| Android:inputmethod |
| Android:inputtype |
| Android:linespacingextra |
| Android:linespacingmultiplier |
| Android:lines |
| Android:linksclickable |
| Android:marqueerepeatlimit |
| Android:maxems |
| Android:maxheight |
| Android:maxlength |
| Android:maxlines |
| Android:maxwidth |
| Android:minems |
| Android:minheight |
| Android:minlines |
| Android:minwidth |
| Android:numeric |
| Android:password |
| Android:phonenumber |
| Android:privateimeoptions |
| Android:scrollhorizontally |
| Android:selectallonfocus |
| Android:shadowcolor |
| Android:shadowdx |
| Android:shadowdy |
| Android:shadowradius |
| Android:singleline |
| Android:text |
| Android:textallcaps |
| Android:textappearance |
| Android:textcolor |
| Android:textcolorhighlight |
| Android:textcolorhint |
| Android:textcolorlink |
| Android:textisselectable |
| Android:textscalex |
| Android:textsize |
| Android:textstyle |
| Android:typeface |
| Android:width |
TextView Inheritance Properties
Inherited XML Attributes
From class Android.view.View
| Attribute Name |
| Android:accessibilityliveregion |
| Android:alpha |
| Android:background |
| Android:clickable |
| Android:contentdescription |
| Android:drawingcachequality |
| Android:duplicateparentstate |
| Android:fadescrollbars |
| Android:fadingedgelength |
| Android:filtertoucheswhenobscured |
| Android:fitssystemwindows |
| Android:focusable |
| Android:focusableintouchmode |
| Android:hapticfeedbackenabled |
| Android:id |
| Android:importantforaccessibility |
| Android:isscrollcontainer |
| Android:keepscreenon |
| Android:layertype |
| Android:layoutdirection |
| Android:longclickable |
| Android:minheight |
| Android:minwidth |
| Android:nextfocusdown |
| Android:nextfocusforward |
| Android:nextfocusleft |
| Android:nextfocusright |
| Android:nextfocusup |
| Android:onclick |
| Android:padding |
| Android:paddingbottom |
| Android:paddingend |
| Android:paddingleft |
| Android:paddingright |
| Android:paddingstart |
| Android:paddingtop |
| Android:requiresfadingedge |
| Android:rotation |
| Android:rotationx |
| Android:rotationy |
| Android:saveenabled |
| Android:scalex |
| Android:scaley |
| Android:scrollx |
| Android:scrolly |
| Android:scrollbaralwaysdrawhorizontaltrack |
| Android:scrollbaralwaysdrawverticaltrack |
| Android:scrollbardefaultdelaybeforefade |
| Android:scrollbarfadeduration |
| Android:scrollbarsize |
| Android:scrollbarstyle |
| Android:scrollbarthumbhorizontal |
| Android:scrollbarthumbvertical |
| Android:scrollbartrackhorizontal |
| Android:scrollbartrackvertical |
| Android:scrollbars |
| Android:soundeffectsenabled |
| Android:tag |
| Android:textalignment |
| Android:textdirection |
| Android:transformpivotx |
| Android:transformpivoty |
| Android:translationx |
| Android:translationy |
| Android:visibility |
That is to say, these two parts add up is TextView all the properties, however, when we edit the code in the XML editor, we will find that in addition to the above attributes, there are many attributes that begin with layout can be set, these are the container properties, the following linearlayout as an example, The experimental scenario is as follows
1 <LinearLayout2 Android:layout_width= "Wrap_content"3 Android:layout_height= "Wrap_content" >4 5 <TextView6 Android:layout_width= "Wrap_content"7 Android:layout_height= "Wrap_content"9 Android:text= "Hello world2" />Ten </LinearLayout>
Let's take a look at the layout properties of LinearLayout, which is represented by the Linearlayout.layoutparams class.
As you can see from the Help document, its own properties are the following:
| XML Attributes |
| Attribute Name |
| Android:layout_gravity |
| Android:layout_weight |
There are two types of attributes inherited, Android.view.ViewGroup.MarginLayoutParams
| Attribute Name |
| Android:layout_marginbottom |
| Android:layout_marginend |
| Android:layout_marginleft |
| Android:layout_marginright |
| Android:layout_marginstart |
| Android:layout_margintop |
and Android.view.ViewGroup.LayoutParams
| Attribute Name |
Related Method |
Description |
| Android:layout_height |
|
Specifies the basic height of the view. |
| Android:layout_width |
|
Specifies the basic width of the view. |
All of the above properties are the layout properties provided by the layout control
Therefore, the properties that TextView can set are the properties of itself and the layout properties above.
Postscript
Above, we analyze the use of the properties of the layout in Android through the combination of linearlayout and textview, so that we can understand the origin of the control properties, so that the layout of the interface will be more arbitrary.
The same reason, can analyze relativelayout, tablelayout and so on.
Original address: http://www.cnblogs.com/luoaz/p/3947100.html
Android Layout Secrets