欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android VelocityTracker使用案例詳解

 更新時(shí)間:2021年08月28日 17:04:28   作者:bigerman  
這篇文章主要介紹了Android VelocityTracker使用案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下

   VelocityTracker顧名思義即速度跟蹤,在android中主要應(yīng)用于touch even。VelocityTracker通過(guò)跟蹤一連串事件實(shí)時(shí)計(jì)算出當(dāng)前的速度,這樣的用法在android系統(tǒng)空間中隨處可見(jiàn),比如Gestures中的Fling, Scrolling等。

   VelocityTracker主要用跟蹤觸摸屏事件(flinging事件和其他gestures手勢(shì)事件)的速率。用addMovement(MotionEvent)函數(shù)將Motion event加入到VelocityTracker類(lèi)實(shí)例中.你可以使用getXVelocity() 或getXVelocity()獲得橫向和豎向的速率到速率時(shí),但是使用它們之前請(qǐng)先調(diào)用computeCurrentVelocity(int)來(lái)初始化速率的單位 。

Public Methods
void addMovement( MotionEventevent) Add a user's movement to the tracker.
void clear() Reset the velocity tracker back to its initial state.
void computeCurrentVelocity(int units, float maxVelocity) Compute the current velocity based on the points that have been collected. intunitis表示速率的基本時(shí)間單位。unitis值為1的表示是,一毫秒時(shí)間單位內(nèi)運(yùn)動(dòng)了多少個(gè)像素, unitis值為1000表示一秒(1000毫秒)時(shí)間單位內(nèi)運(yùn)動(dòng)了多少個(gè)像素 floatVelocity表示速率的最大值
void computeCurrentVelocity(int units) Equivalent to invoking computeCurrentVelocity(int, float)with a maximum velocity of Float.MAX_VALUE. 一般使用此函數(shù)即可
abstract T getNextPoolable()
float getXVelocity() Retrieve the last computed X velocity.
float getXVelocity(int id) Retrieve the last computed X velocity.
float getYVelocity(int id) Retrieve the last computed Y velocity.
float getYVelocity() Retrieve the last computed Y velocity.
abstract boolean isPooled()
static VelocityTracker obtain() Retrieve a new VelocityTracker object to watch the velocity of a motion.
void recycle() Return a VelocityTracker object back to be re-used by others.
abstract void setNextPoolable(T element)
abstract void setPooled(boolean isPooled)

示例代碼:

@Override
	    public boolean onTouchEvent(MotionEvent ev) {
 
	        if (null == mVelocityTracker) {
	            mVelocityTracker = VelocityTracker.obtain();
	        }
	        mVelocityTracker.addMovement(ev);
 
	        switch (ev.getAction()) {
	            case MotionEvent.ACTION_UP:
	                // 隱藏在左邊的寬度
	                int scrollX = getScrollX();
	                Loger.e(ObjEarth.TAG, "V=" + mVelocityTracker.getXVelocity());
	                if (Math.abs(mVelocityTracker.getXVelocity()) > 4000f) {
	                    if (mVelocityTracker.getXVelocity() < 0f) {
	                        //正向邏輯代碼
	                    } else {
	                        //反向邏輯代碼
	                    }
	                }
	                return true;
	            case MotionEvent.ACTION_MOVE:
	                mVelocityTracker.computeCurrentVelocity(1000); //設(shè)置units的值為1000,意思為一秒時(shí)間內(nèi)運(yùn)動(dòng)了多少個(gè)像素
	        }
	        return super.onTouchEvent(ev);
	    }

到此這篇關(guān)于Android VelocityTracker使用案例詳解的文章就介紹到這了,更多相關(guān)Android VelocityTracker使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論