Custom Combo control, adapter principle-day31 mobile2.1
- Home Page Definition
- Phone Lock function
1. Eject the Set Password box.
- Mobile Download Progress
- Customizing the definition Control
The property of a control is actually a set method method that sets the property of the control class to invoke the class.
Ideas for customizing composite controls
- Life an
View
object inherits from relative layout, linear layout, or otherViewGroup
- The
View
object overrides the construction method, and then initializes the layout by View.inflate()
means of a method to hang our own defined layout into the interface.
- Custom attributes are
res/values
created inside the directory attrs.xml
to define some properties,
<resources
<declare-styleable name= " Cn.itcast.phonesafe.view.SettingView ";
< attr name= "Setting_title" format= " string "/>
<attr name= " des_on " format= "string" />
<attr name= "Des_off" format= "string" />
</declare-styleable>
</resources>
Namespace of the Life custom attributexmlns:zl_pro="http://schemas.android.com/apk/res/cn.zlpro.mobilesafe"
We can use the controls we have defined in the current layout 1条
.
- Gets the property by customizing the constructor of the function.
AttributeSet
attrs
the inside can be obtained
title = attrs.getAttributeValue( "http://schemas.android.com/apk/res/cn.zlpro.mobilesafe","setting_title");
Summary: A custom control is a control that we do not use with a system definition, we define it ourselves, the control is a class, we can put this class into our layout file. Now there are many that can be
LayoutinflaterSimple principle
LayoutInflater
is by pull
parsing the layout of the XML file internally called the createViewFromTag()
method has nodes and parameters, and then to call the internal createView()
method, the use of reflection to create View
, so that the layout of the DOM structure in a recursive way to fully reflect the creation of the View
object
Drawing principle
The drawing process of the view must go through the three most important stages, that onMeasure()
is, measuring, onLayout()
determining position and onDraw()
drawing, drawing to our screen, note that View
will not help me to draw graphics, so each content needs to be self-drawing TextView
ImageView
rewrite onDraw()
method, which is used to draw the main use of Canvas
this class.
Source code final View view = createViewFromTag(name, attrs);
This line of code to create a V View
object, and finally added to the parent node. Finally, recursively, you can draw all the layouts to the window.
Reference blog:
Layoutinflater principle Analysis, step by step to understand the view (a)
The Android view drawing process is fully parsed, and takes you step into a deeper understanding of view (ii)
Android View status and redraw process analysis, take you step-by-piece insight into view (iii)
The Android Custom View implementation method, takes you step by step deep understanding view (four)
Introduction to Android Custom control development
Problem area
- Adapter Monitoring principle
ListView
For each of the list item
, ask adapter
"Give me A View" (GetView). So at the setAdapter()
time of the method is to give a can get loaded into the current containerView生成器
- How the control implements the listener.
The principle of custom controls, the function of constructors完成
In fact, even when LayoutInflater
loading into the layout, through reflection response View
, if pull
resolved to the node will call the modification method, draw the corresponding view, the source code final View view = createViewFromTag(name, attrs);
this line of code to create the V View
object, and finally added to the parent node. In the end, all the layouts can be drawn to the window with recursive recursion.
How to judge a child thread UI thread
- Learn
google
the latest design language
Experience
- Post-Lite code, the code is finished, the interface logic assembly
- After the teacher's class code can not be dragged to the post-processing.
Creative
- Video to add your own tech reviews
Custom composite control, adapter principle-day31