最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android VelocityTracker使用案例詳解

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

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

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

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)動了多少個(gè)像素, unitis值為1000表示一秒(1000毫秒)時(shí)間單位內(nèi)運(yùn)動了多少個(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)動了多少個(gè)像素
	        }
	        return super.onTouchEvent(ev);
	    }

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

相關(guān)文章

最新評論

绥中县| 岢岚县| 合肥市| 青州市| 德化县| 盐源县| 天台县| 东兴市| 连江县| 马公市| 开平市| 鄂伦春自治旗| 资阳市| 东光县| 丰顺县| 新沂市| 荣昌县| 西平县| 邵阳市| 文水县| 财经| 江山市| 繁昌县| 桦川县| 绥德县| 茌平县| 宁远县| 三门县| 图木舒克市| 浦城县| 乌什县| 岐山县| 定南县| 江北区| 涞水县| 郸城县| 民丰县| 伊春市| 拉萨市| 卢氏县| 泸州市|