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