Android Custom View Analysis

Source: Internet
Author: User

First, the basic steps

1. Custom View Properties

2. Get custom attributes in the view's construction method

3. Overriding the Onmesure method (not required)

4. Overriding the OnDraw method

Second, the concrete realization

1, custom View properties, first set up a attrs.xml under the res/values/

Then use it in the layout file, where the red Arrow is followed by the project package name, so that you can use the shortcut keys to elicit the custom properties.

2. Get our custom properties in the View construction method

3, if necessary, must rewrite onmeasure

Before rewriting, understand Measurespec's specmode, altogether three kinds:

Exactly: The general setting of a definite value or a match_parent

At_most: Indicates that the child layout is limited to a maximum value, typically warp_content

UNSPECIFIED: Indicates how large a sub-layout is to be, rarely used

4. Overriding the OnDraw method

4, the Operation effect, click View can randomly change the value, similar to the verification code.

Android Custom View Analysis

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.