Android--------Custom Controls (i)

Source: Internet
Author: User

We often deal with controls in our normal Android development, and sometimes Android-provided controls don't necessarily meet the needs of the business, and this time we need to implement custom controls

Custom controls can design many of the features and modules you want, which is an important part of development.

Value of Custom View
    • Can do the basic control can not do the effect, for the performance of the application;

    • A team that develops in parallel with multiple applications, extracts the common interaction effects into custom controls, facilitates reuse, and reduces unnecessary duplication of labor;

    • The internal logic of the control is encapsulated in a custom view to facilitate in-application decoupling;

Flow chart:

There are two ways of customizing controls:

1. Inheriting ViewGroup

Custom ViewGroup typically use existing components to compose new components based on a particular layout, mostly inherited from ViewGroup or various layouts, including sub-view.

For example: ViewGroup, LinearLayout, Framelayout, Relativelayout and so on.

2. Inherit view

In the absence of a ready-made view, you need to implement it yourself, using a custom view, generally inherited from View,surfaceview or other view, does not include child view.

For example: View, TextView, ImageView, button, and so on.

The three core methods of view onmeasure, OnLayout, OnDraw
    • onmeasure: used to measure the size of the view;

    • onlayout: used to lay out the view;

    • OnDraw: used to draw the view;

These three methods are very important, the next blog in detail to explain

Android--------Custom Controls (i)

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.