Some of the unknown details of Android Custom view

Source: Internet
Author: User

Reason: The reason why I write this is because I think I know the custom view, but later found that I made a lot of low-level errors.
In detail: According to the source code annotation, the view drawing process is this kind of son:
                 /* * Draw Traversal performs several drawing steps which must be executed * in the         appropriate order:         *         *< C5/>1. Draw the background         *      2. If necessary, save the canvas ' layers to prepare for fading         *      3. Draw View ' s content         *      4. Draw Children         *      5. If necessary, draw the fading edges and restore layers         *      6. Draw Decorations (scrollbars for instance)         */

Draw the background first, if necessary, save the canvas layer, draw the content, draw the child, draw the gradient, draw the decorations. Let's look at the code in the source draw () method
  if (!verticaledges &&!horizontaledges) {            //Step 3, draw the content            if (!dirtyopaque) OnDraw (canvas); 
   //Step 4, draw the children            Dispatchdraw (canvas);            Step 6, Draw decorations (scrollbars)            ondrawscrollbars (canvas);            We ' re done ...            return;        }
From here we can see that the call process of the draw method is like this.
OnDraw, <span style= "font-family:arial, Helvetica, Sans-serif;" >dispatchdraw, </span><span style= "font-family:arial, Helvetica, Sans-serif;" >onDrawScrollBars</span>
In this way we can basically understand what our rewritten OnDraw method is, and the relationship of Draw () OnDraw () Dispatchdraw. If you want to draw at the top level, rewrite the draw method directly, because the Draw method contains OnDraw and Dipatchdraw. In fact, the main want to write a detail is this thing. If you want to make something that you draw all the way around the control, it must be written like this.Canvas.translate (Getscrollx (), getscrolly ());
There's no explanation here, I know what I said before, and I knew why I was writing it. I rewrote the ListView and found that the control I wrote was jumping frame, which was when the fading edges appeared on the slide, only to find out for this reason.

Some of the unknown details of Android Custom view

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.