Android Scroller完全解析臼氨,關(guān)于Scroller你所需知道的一切
Scroller
構(gòu)造函數(shù)
- Scroller(Context context)
- Scroller(Context context, Interpolator interpolator)動畫插入器
- Scroller(Context context, Interpolator interpolator, boolean flywheel)费就,overScroller的flinging(具體使用未知)
常用的方法
computeScrollOffset()
判斷Scroller的數(shù)值是否還在變化中,true為變化中拉队,false為變化完成蚀浆。
startScroll (int startX, int startY, int dx, int dy)
開始數(shù)值變化,前倆個參數(shù)為起始的X诲泌、Y值,后面?zhèn)z個是對應(yīng)的偏移量(偏移量:左上為正,右下為負(fù)铣鹏。默認(rèn)偏移時間為250毫秒敷扫,可以自己加個時間參數(shù)。)
Scroller.getCurrX()
得到當(dāng)前變化的X
Scroller.getCurrY()
得到當(dāng)前變化的Y
使用
- 在自定義view的構(gòu)造方法中初始化Scroller
- 調(diào)用Scroller的
startScroll (int startX, int startY, int dx,int dy)
開始滾動
并且記得刷新繪制
invalidate();
- 重寫函數(shù)
computeScroll()
```
這里很重要!很重要!很重要!!!
一般情況下
```
@Override
public void computeScroll() {
if(mScroller.computeScrollOffset()){
scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
invalidate();
}
}
```
----
**[ScrollerDemo](https://github.com/minminaya/ScrollerDemo)**
---
end