Android Custom View onmeasure in Super.onmeasure and setmeasureddimension

Source: Internet
Author: User

Practice writing a custom view, the code is copied online, the first write, no problem, with the online example of the effect,

The second and third time, there are problems, but solved.

The fourth time yesterday to write and write again, the problem is not the same.

The first is to add a child package, the result of the app on the directory directly create the child package full name, the result of the child package level and the parent package sibling directory. But the child package name is added directly to the parent package, and the child package directory can be in the parent package directory.

Second encounter, the custom view is always displayed, after careful comparison, found to be in the rewrite onmeasure after the call super.onmeasure (width,height);

Super.onmeasure should be the parameters of the and Onmeasure methods:widthmeasurespec and Heightmeasurespec, after recalculating the width and height, should be using Setmeasureddimension (width,height).

I do for Android novice, English level general, just record their own mistakes, master do not like to vomit.

Some pits, do not tread do not know!

Android Custom View onmeasure in Super.onmeasure and setmeasureddimension

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.