Custom Combo control, adapter principle-day31

Source: Internet
Author: User

Custom Combo control, adapter principle-day31 mobile2.1
    1. Home Page Definition
    2. Phone Lock function

1. Eject the Set Password box.

    1. Mobile Download Progress
    2. 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
    1. Life an View object inherits from relative layout, linear layout, or otherViewGroup
    2. 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.
    3. 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>
    1. Namespace of the Life custom attributexmlns:zl_pro="http://schemas.android.com/apk/res/cn.zlpro.mobilesafe"

    2. We can use the controls we have defined in the current layout 1条 .

    3. 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

LayoutInflateris 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
    1. Adapter Monitoring principle

      ListViewFor 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生成器



    1. How the control implements the listener.
    2. 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.

    3. How to judge a child thread UI thread

    4. Learn google the latest design language
Experience
    1. Post-Lite code, the code is finished, the interface logic assembly
    2. After the teacher's class code can not be dragged to the post-processing.
Creative
    1. Video to add your own tech reviews

Custom composite control, adapter principle-day31

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.