android自定义布局中的平滑移动

  


,这里就不详细介绍了


android.view.VelocityTracker   android.view.Scroller   android.view。ViewConfiguration



<李> void  init (Context 上下文),{   ,,,,,,,,,,,,,,,mScroller =, new 照片卷轴(getContext ());   ,,,,,,,,,,,,,,,setFocusable(真正的);   ,,,,,,,,,,,,,,,setDescendantFocusability (FOCUS_AFTER_DESCENDANTS);   ,,,,,,,,,,,,,,,setWillNotDraw(假);   ,,,,,,,,,,,,,,,final  ViewConfiguration  configuration =, ViewConfiguration.get(上下文);   ,,,,,,,,,,,,,,,mTouchSlop =, configuration.getScaledTouchSlop ();   ,,,,,,,,,,,,,,,mMinimumVelocity =, configuration.getScaledMinimumFlingVelocity ();   ,,,,,,,,,,,,,,,mMaximumVelocity =, configuration.getScaledMaximumFlingVelocity ();   ,,,,,,,}

<强> Java代码 <李> public  void 舞(int  velocityY), {   ,,,,,,,if  (getChildCount(),祝辞,0),{   ,,,,,,,,,,,,,,,mScroller.fling (getScrollX (),, getScrollY (),, 0,, velocityY,, 0, 0, 0,   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,maxScrollEdge);   ,,,,,,,,,,,,,,,final  boolean  movingDown =, velocityY 祝辞,0;   ,,,,,,,,,,,,,,,awakenScrollBars (mScroller.getDuration ());   ,,,,,,,,,,,,,,,invalidate ();   ,,,,,,,}   李}


<强> Java代码 <李> private  void  obtainVelocityTracker (MotionEvent 事件),{   ,,,,,,,if  (mVelocityTracker ==, null), {   ,,,,,,,,,,,,,,,mVelocityTracker =, VelocityTracker.obtain ();   ,,,,,,,}   ,,,,,,,mVelocityTracker.addMovement(事件);   }   private  void  releaseVelocityTracker (), {   ,,,,,,,if  (mVelocityTracker  !=, null), {   ,,,,,,,,,,,,,,,mVelocityTracker.recycle ();   ,,,,,,,,,,,,,,,mVelocityTracker =,空;   ,,,,,,,}   李}

<强> Java代码 <李>

公共布尔> <李>

公共空computeScroll () {

<李>

,,,,如果(mScroller.computeScrollOffset ()) {

<李>

,,,,,,,,int scrollX=getScrollX ();

<李>

,,,,,,,,int scrollY=getScrollY ();

<李>

,,,,,,,,int oldX=scrollX;

<李>

,,,,,,,,int老人=scrollY;

<李>

,,,,,,,,int x=mScroller.getCurrX ();

<李>

,,,,,,,,int y=mScroller.getCurrY ();

<李>

,,,,,,,,scrollX=x;

<李>

,,,,,,,,scrollY=y;

<李>

,,null

android自定义布局中的平滑移动