1.scrolltoåscrollbyçåºå«
scrolltoåscrollbyçåºå«
ããViewç±»çæºä»£ç å¦ä¸æ示ï¼mScrollXè®°å½çæ¯å½åViewé对å±å¹åæ å¨æ°´å¹³æ¹åä¸çå移éï¼èmScrollYåæ¯è®°å½çæ¶å½åViewé对å±å¹å¨ç«å¼æ¹åä¸çå移éã
ããä»ä»¥ä¸ä»£ç å¯ä»¥å¾ç¥ï¼scrollToå°±æ¯æView移å¨å°å±å¹çXåYä½ç½®ï¼ä¹å°±æ¯ç»å¯¹ä½ç½®ãèscrollByå ¶å®å°±æ¯è°ç¨çscrollToï¼ä½æ¯åæ°æ¯å½åmScrollXåmScrollYå ä¸XåYçä½ç½®ï¼æ以ScrollByè°ç¨çæ¯ç¸å¯¹äºmScrollXåmScrollYçä½ç½®ãå¨ä¸é¢ç代ç ä¸å¯ä»¥çå°å½ææä¸æ¾ç§»å¨å±å¹æ¶ï¼å°±ä¼è°ç¨scrollByæ¥ç§»å¨ä¸æ®µç¸å¯¹çè·ç¦»ãèå½æ们æææ¾å¼åï¼ä¼è°ç¨ mScroller.startScroll(mUnboundedScrollX,源码kodi 没有 源码输出 0, delta, 0, duration);æ¥äº§çä¸æ®µå¨ç»æ¥ç§»å¨å°ç¸åºç页é¢ï¼å¨è¿ä¸ªè¿ç¨ä¸ç³»ç»åä¸æè°ç¨computeScroll()ï¼å使ç¨scrollToæ¥æView移å¨å°å½åScrolleræå¨çç»å¯¹ä½ç½®ã
ãã/
*** Set the scrolled position of your view. This will cause a call to
* { @link #onScrollChanged(int, int, int, int)} and the view will be
* invalidated.
* @param x the x position to scroll to
* @param y the y position to scroll to
*/
public void scrollTo(int x, int y) {
if (mScrollX != x || mScrollY != y) {
int oldX = mScrollX;
int oldY = mScrollY;
mScrollX = x;
mScrollY = y;
invalidateParentCaches();
onScrollChanged(mScrollX, mScrollY, oldX, oldY);
if (!awakenScrollBars()) {
invalidate(true);
}
}
}
/
*** Move the scrolled position of your view. This will cause a call to
* { @link #onScrollChanged(int, int, int, int)} and the view will be
* invalidated.
* @param x the amount of pixels to scroll by horizontally
* @param y the amount of pixels to scroll by vertically
*/
public void scrollBy(int x, int y) {
scrollTo(mScrollX + x, mScrollY + y);
}