/**
* Helper for tracking the velocity of touch events, for implementing
* flinging and other such gestures. Use {@link #obtain} to retrieve a
* new instance of the class when you are going to begin tracking, put
* the motion events you receive into it with {@link #addMovement(MotionEvent)},
* and when you want to determine the velocity call
* {@link #computeCurrentVelocity(int)} and then {@link #getXVelocity()}
* and {@link #getXVelocity()}.
*/
這是注釋,在android 應用程序的開發過程中,可以實現比較絢麗,比如讓界面切換平滑的滾動,系統提供的應用在特效這方面提供簡單的動畫接口,
自定義控件開發做一些簡單的介紹,
自定義布局控件自然是要繼承某個View 或 ViewGroup
開發自定義的ViewGroup 自然是要繼承ViewGroup 類,
在繼承這個類之后,必須重寫的方法就是
OnLayout(boolean changed ,int i int t int r ,int b);
想要對布局控件以及其子控件的尺寸進行精確控制,重寫
onMeasure(int widthMeasure,int heightMeasureSpec);
介紹關於自定義控件進行平滑的移動,並能夠根據手勢的情況禪城慣性滑動的效果
滑動效果需要的各種工具
android.view.VelocityTracer;
android.view.Scroller;
android.view.ViewConfiguration
VelocityTracker從字面意思理解那就是速度追蹤器了,在滑動效果的開發中通常都是要使用該類計算出當前手勢的初始速度(不知道我這么理解是否正確,對應的方法是velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity))並通過getXVelocity或getYVelocity方法得到對應的速度值initialVelocity,並將獲得的速度值傳遞給Scroller類的fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)方法進行控件滾動時各種位置坐標數值的計算,API中對fling方法的解釋是基於一個fling手勢開始滑動動作,滑動的距離將由所獲得的初始速度initialVelocity來決定。關於ViewConfiguration的使用主要使用了該類的下面三個方法:
configuration.getScaledTouchSlop()//獲得能夠進行手勢滑動的距離
configuration.getScaledMinimumFlingVelocity()//獲得允許執行一個fling手勢動作的最小速度值
configuration.getScaledMaximumFlingVelocity()//獲得允許執行一個fling手勢動作的最大速度值
需要重寫的方法至少要包含下面幾個方法:
onTouchEvent(MotionEvent event)//有手勢操作必然少不了這個方法了
computeScroll()//必要時由父控件調用請求或通知其一個子節點需要更新它的mScrollX和mScrollY的值。典型的例子就是在一個子節點正在使用Scroller進行滑動動畫時將會被執行。所以,從該方法的注釋來看,繼承這個方法的話一般都會有Scroller對象出現。
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1114/558.html