Preface
This chapter content is android. widget. AbsoluteLayout, version for Android 2.2 r1, translated from madgoat, welcome to visit his blog: http://madgoat.cn/, thanks again madgoat! I look forward to your participation in Android API Chinese translation, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog Garden: http://www.cnblogs.com/
Android Chinese translation group: http://www.cnblogs.com/over140/
Body
I. Structure
Public class AbsoluteLayout extends ViewGroup
Java. lang. Object
Android. view. View
Android. view. ViewGroup
Android. widget. AbsoluteLayout
This class does not support use.
RecommendedFrameLayout
,RelativeLayout
Or use custom layout instead.
Ii. Overview
Let you specify the precise coordinate layout of the xy of the child element. The absolute layout lacks flexibility and is more difficult to maintain than other la s without absolute positioning.
Iii. Public Methods
Public ViewGroup. LayoutParams generateLayoutParams (AttributeSet attrs)
Returns a set of new layout Parameters Based on the supported attribute sets.
Parameters
Attrs builds a set of layout Parameters
Return Value
An instance of ViewGroup. LayoutParams or a subclass of it
Iv. Protected Methods
Protected ViewGroup. LayoutParams generateLayoutParams (ViewGroup. LayoutParams p)
Returns a combination of supported layout parameters. This method is called when a ViewGroup passes a view that is not detected by the layout parameter checkLayoutParams (android. view. ViewGroup. LayoutParams. This method returns a new set of layout parameters suitable for the current ViewGroup. You may copy the appropriate attributes from a specified set of layout parameters.
Parameters
P is converted into a set of layout parameters suitable for the current ViewGroup.
Return Value
An instance of ViewGroup. LayoutParams or one of its descendants
An instance of ViewGroup. LayoutParams or a subnode
Protected boolean checkLayoutParams (ViewGroup. LayoutParams p)
(Note: Check whether the instance is AbsoluteLayout. LayoutParams. For details, see the source code:
Protected ViewGroup. LayoutParams generateDefaultLayoutParams ()
Returns a set of layout parameters with the width of WRAP_CONTENT, height of WRAP_CONTENT, and coordinates of (0, 0 ).
Return Value
A set of default layout parameters or null values
Protected void onLayout (boolean changed, int l, int t, int r, int B)
This view is called when the size and position of each of its child elements are allocated. A derived class can override this method and reschedule the layout of its subclass.
Parameters
Changed this is a new size or position of the current view.
L left position relative to the parent node
T vertex position relative to the parent node
R's right position relative to the parent node
The bottom position of B relative to the parent node
Protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
Measure the view to determine its content width and height. This method is called by measure (int, int. The quilt class needs to be overwritten to provide accurate and efficient measurement of its content.
Convention: When you override this method, you must call setMeasuredDimension (int, int) to save the width and height of the current view. If this method is not successfully called, an IllegalStateException exception is thrown by measure (int, int. Therefore, the onMeasure (int, int) method of the parent class is required.
The implementation of the parent class is based on the Default background size, unless MeasureSpec (measurement rules) allows a larger background. Subclass can override onMeasure (int, int) to provide a better size for its content.
If this method is overwritten, The subclass is responsible for confirming that the measurement height and width are greater than the minimum width and minimum height of the view (getSuggestedMinimumHeight () and getSuggestedMinimumWidth ()), use these two methods to obtain the minimum width and the minimum height.
Parameters
Horizontal space requirements imposed by widthMeasureSpec on the parent node. The requirement is to use View. MeasureSpec for encoding.
The vertical spatial requirements imposed by heightMeasureSpec on the parent node. View. MeasureSpec must be used for encoding.
5. Supplement
Article Link
My Android learning journey [6] -- demonstrate several Android la s with sample programs
Lecture 6: User Interface View (2)
How to dynamically change the coordinates of other la s in the AbsoluteLayout Layout
Sample Code
<AbsoluteLayout
Android: id = "@ + id/AbsoluteLayout01" android: layout_height = "wrap_content"
Android: layout_width = "fill_parent">
<TextView
Android: text = "TextView01" android: id = "@ + id/TextView01"
Android: layout_height = "wrap_content" android: layout_y = "10px"
Android: layout_width = "wrap_content" android: layout_x = "110px">
</TextView>
</AbsoluteLayout>
End
The declared image is from article 1.