Android custom View study notes

scrollTo与scrollBy

Pick the important ones:

  • scrollBy is the scrollTo method that is called internally: scrollTo(mScrollX + x, mScrollY + y);   ;
  • The scrollTo and scrollBy methods move the content of the View, that is, to move the content of the View; if the scrollBy and scrollTo methods are used in the ViewGroup, then all the child Views in the ViewGroup are moved, but if they are used in the View, the moving will be the content of the View. For example : TextView, content is his text, ImageView, content is its drawable object.
MyView internal call:
((View) getParent()).scrollBy(offsetX, offsetY);
 External call:
((View) myView.getParent()).scrollBy(offsetX, offsetY);

It is equivalent to a layer of cover with eyes on the content of MyView (MyView itself). When the scrollTo and scrollBy methods are called, the cover is moved.

  • scrollTo, scrollBy moving to the right or down is a negative value, moving up or left is a positive value;

mScrollX and mScrollY

  • mScrollX represents the horizontal distance from the left edge of the view to the left edge of the content of the view. Similarly, mScrollY represents the vertical distance between the upper edge of the view and the upper edge of the content of the view;
  • The two are obtained through the getScrollX() and getScrollY() methods respectively;
  • mScrollX and mScrollY do not refer to coordinates, but to offsets (distances).

Reference: Sliding exploration of android layout instructions for scrollTo and scrollBy methods

     A preliminary study of sliding screen in Android ---- scrollTo and scrollBy method instructions

   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324972125&siteId=291194637