Revealing the layout of Android and revealing the secrets of android
Preface
Today, I will write down some understanding of the layout. The main content includes the inheritance relationship between the control attributes, the relationship between the control attributes and the container attributes, and the use of various types of attributes.
Property type of the control
Generally speaking, when assigning values to attributes of a control, there are generally some types of attributes, one starting with layout, one is an attribute that does not start with layout _. TextView is used as an example to describe it as follows:
1 <RelativeLayout 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" > 4 5 <TextView 6 android:layout_width="wrap_content" 7 android:layout_height="wrap_content" 8 android:text="hello_world" /> 9 10 </RelativeLayout>
I have set three attributes layout_width, layout_height, and text for TextView. We can see that the layout_width and layout_height attributes of the three attributes start with layout _, while the text attributes do not start with Layout.
Attributes starting with layout _ are inherited from the container. In this example, they are inherited from RelativeLayout, and TextView itself does not. Text is the property of TextView.
To illustrate that the layout attribute is a container attribute, I used the following example to place the TextView in RelativeLayout and LinearLayout, and set the layout_centerInParent attribute for the TextView, this is because this attribute is RelativeLayout and LinearLayout does not. The experiment code is as follows:
1 <RelativeLayout 2 android:layout_width="wrap_content" 3 android:layout_height="wrap_content" > 4 5 <TextView 6 android:layout_width="wrap_content" 7 android:layout_height="wrap_content" 8 android:layout_centerInParent="true" 9 android:text="hello_world" />10 </RelativeLayout>11 12 <LinearLayout13 android:layout_width="wrap_content"14 android:layout_height="wrap_content" >15 16 <TextView17 android:layout_width="wrap_content"18 android:layout_height="wrap_content"19 android:layout_centerInParent="true"20 android:text="hello world2" />21 </LinearLayout>
After the preceding settings, the editor prompts "Invalid layout param in a LinearLayout: layout_centerInParent", as shown below:
Through this experiment, we can draw a conclusion that the attribute starting with layout is not owned by TextView, but inherits the layout attribute in the container. Then, we can draw a conclusion, controls can be divided into their own attributes and the layout attributes in the container. Next we will analyze the attributes in detail through TextView and each layout container.
LinearLayout and TextView
This section describes the attributes of LinearLayout and TextView. First, let's take a look at the attributes of TextView and the property inheritance relationship,
The attributes of TextView are as follows:
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 inherited attributes
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: scrollbardefadeldelaybeforefade |
Android: scrollbarFadeDuration |
Android: scrollbarSize |
Android: scrollbarStyle |
Android: scrollpolicumbhorizontal |
Android: scrollpolicumbvertical |
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 are all attributes of TextView. However, when we edit the code in the XML editor, we will find that in addition to the above attributes, there are also many attributes starting with layout that can be set, these are the container attributes. The following uses LinearLayout as an example. The experiment scenario is as follows:
1 <LinearLayout 2 android:layout_width="wrap_content" 3 android:layout_height="wrap_content" > 4 5 <TextView 6 android:layout_width="wrap_content" 7 android:layout_height="wrap_content" 9 android:text="hello world2" />10 </LinearLayout>
Next, let's take a look at the layout attributes of LinearLayout, which are embodied in the LinearLayout. LayoutParams class.
The help document shows that its attributes are as follows:
XML Attributes |
Attribute Name |
Android: layout_gravity |
Android: layout_weight |
Two types of attributes are 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 the preceding attributes are the layout Attributes provided by the layout control.
Therefore, the attributes that TextView can set are its own attributes and the preceding layout attributes.
Postscript
We have analyzed the attribute usage of the layout in Android through the combination of LinearLayout and TextView. Through the above analysis, we can understand the origin of the control property, in this way, you can make the interface layout as you like.
Similarly, you can analyze RelativeLayout, TableLayout, and so on.
Address: http://www.cnblogs.com/luoaz/p/3947100.html
Android layout selection call
Extends activityGroup
Add a ScrollView to the xml framework layout.
<ScrollView android: measureAllChildren = "true" android: id = "@ + id/aa"
Android: layout_weight = "1" android: layout_height = "fill_parent"
Android: layout_width = "fill_parent">
</ScrollView>
In the Code:
Aa. removeAllViews ();
Aa. addView (getLocalActivityManager (). startActivity (
"Module1 ",
New Intent (this, xml2.class)
. AddFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP ))
. GetDecorView ());
How to Implement the layout of android
If there are no Fragments in the lower part of 3.0, after you layout the left and right sides, update the corresponding view based on the click event.