In the preceding article, we have a general understanding of the handling of Android touch events, and have explored the relevant usage of motionevent in detail. The knowledge of the previous article is not a very familiar classmate, please read "Android motionevent detailed"
Today, we will discuss the mechanism of the interface scrolling effect in Android, this article mainly explains the rolling related knowledge points, the later article will involve the actual code and the principle. I hope that after reading this article, we can understand or grasp the knowledge:
Parts of Android View
Mscrollx and mscrolly effects of view display
Use of Scrollto and Scrollby
The difference between invalidate and postinvalidate
View of MSCROLLX and mscrolly
As we all know, there are two important member variables in view, mscrollx,mscrolly. They represent the horizontal and vertical scrolling distance of the view content (app development ty300.com). We can use SETSCROLLX and setscrolly to change their values to scroll through the contents of the view.
It should be emphasized here that MSCROLLX and mscrolly cause the view content to change, but not affect the view background (background).
See here the students may have to write a question, the view of the content and background what is the difference? What other parts of the view are there?
We can learn about the part of the view from the draw method of view.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/view/ View.java#view
Public void draw(canvas canvas) {
........
/*
* Draw traversal performs several drawing steps which must be executed
* In the appropriate order:
*
* 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)
*/
//Step 1, draw the background, if needed
if (! Dirtyopaque) {
drawbackground(canvas);
}
.......
//Step 2, Save the canvas ' layers
.......
//Step 3, draw the content
if (! Dirtyopaque) onDraw(canvas);
//Step 4, Draw the children
dispatchdraw(canvas);
//Step 5, draw the fade effect and restore layers
.......
if (drawtop) {
Matrix. Setscale(1, fadeheight * topfadestrength);
Matrix. Posttranslate(left, top);
fade. Setlocalmatrix(matrix);
P. Setshader(fade);
Canvas. DrawRect(left, top, right , top + length, p );
}
.....
//Step 6, Draw decorations (scrollbars)
ondrawscrollbars(canvas);
......
}
The view display is made up of a few parts:
Background (background)
The contents of itself (content)
Child view
The boundary gradient effect (fade effect), which can have a gradient effect on the upper and lower four boundaries, shows only the gradient rendering of the upper boundary in the code.
A border or decorative effect (decorations), such as a scroll bar
As an example, we all know that in a layout file, TextView has two more important properties: Background,text. Background can set the background of the TextView, while text sets the font content to be drawn.
Manuscripts: Diligent Learning qkxue.net
Read full Android Scroll detailed
Android Scroll Detailed