2015-04-19 68 views
0

我想了解如何處理android中的圖像和手勢功能。 因此,我閱讀Android開發人員網站的「動畫滾動手勢」部分下的示例「InteractiveChart」。 雖然我在InteractiveLineGraphView.java中閱讀了關於「onDoubleTap」方法。關於android開發人員示例「InteractiveChart」中的「onDoubleTap」功能,

 @Override 
     public boolean onDoubleTap(MotionEvent e) { 
      mZoomer.forceFinished(true); 
      if (hitTest(e.getX(), e.getY(), mZoomFocalPoint)) { 
      mZoomer.startZoom(ZOOM_AMOUNT); 
      } 
      ViewCompat.postInvalidateOnAnimation(InteractiveLineGraphView.this); 
      return true; 
     } 

我檢查了Zoomer的代碼。 它主要調用DecelerateInterpolator方法並設置一些變量。 我想知道「Zoomer」如何實現雙擊縮放功能。 「DecelerateInterpolator」是否做這項工作?或者我錯過了什麼?

public class Zoomer { 
/** 
* The interpolator, used for making zooms animate 'naturally.' 
*/ 
private Interpolator mInterpolator; 

/** 
* The total animation duration for a zoom. 
*/ 
private int mAnimationDurationMillis; 

/** 
* Whether or not the current zoom has finished. 
*/ 
private boolean mFinished = true; 

/** 
* The current zoom value; computed by {@link #computeZoom()}. 
*/ 
private float mCurrentZoom; 

/** 
* The time the zoom started, computed using {@link android.os.SystemClock#elapsedRealtime()}. 
*/ 
private long mStartRTC; 

/** 
* The destination zoom factor. 
*/ 
private float mEndZoom; 

public Zoomer(Context context) { 
    mInterpolator = new DecelerateInterpolator(); 
    mAnimationDurationMillis = context.getResources().getInteger(
      android.R.integer.config_shortAnimTime); 
} 

/** 
* Forces the zoom finished state to the given value. Unlike {@link #abortAnimation()}, the 
* current zoom value isn't set to the ending value. 
* 
* @see android.widget.Scroller#forceFinished(boolean) 
*/ 
public void forceFinished(boolean finished) { 
    mFinished = finished; 
} 

/** 
* Aborts the animation, setting the current zoom value to the ending value. 
* 
* @see android.widget.Scroller#abortAnimation() 
*/ 
public void abortAnimation() { 
    mFinished = true; 
    mCurrentZoom = mEndZoom; 
} 

/** 
* Starts a zoom from 1.0 to (1.0 + endZoom). That is, to zoom from 100% to 125%, endZoom should 
* by 0.25f. 
* 
* @see android.widget.Scroller#startScroll(int, int, int, int) 
*/ 
public void startZoom(float endZoom) { 
    mStartRTC = SystemClock.elapsedRealtime(); 
    mEndZoom = endZoom; 

    mFinished = false; 
    mCurrentZoom = 1f; 
} 

/** 
* Computes the current zoom level, returning true if the zoom is still active and false if the 
* zoom has finished. 
* 
* @see android.widget.Scroller#computeScrollOffset() 
*/ 
public boolean computeZoom() { 
    if (mFinished) { 
     return false; 
    } 

    long tRTC = SystemClock.elapsedRealtime() - mStartRTC; 
    if (tRTC >= mAnimationDurationMillis) { 
     mFinished = true; 
     mCurrentZoom = mEndZoom; 
     return false; 
    } 

    float t = tRTC * 1f/mAnimationDurationMillis; 
    mCurrentZoom = mEndZoom * mInterpolator.getInterpolation(t); 
    return true; 
} 

/** 
* Returns the current zoom level. 
* 
* @see android.widget.Scroller#getCurrX() 
*/ 
public float getCurrZoom() { 
    return mCurrentZoom; 
} 

}

可有人還建議有關形象和姿態處理一些偉大的樣品?從基礎到高級.....非常感謝。

回答

0

的雙擊在InteractiveLineGraphView觀點實際上是損害了自身

@Override 
public boolean onDoubleTap(MotionEvent e) { 
    mZoomer.forceFinished(true); 
    if (hitTest(e.getX(), e.getY(), mZoomFocalPoint)) { 
      mZoomer.startZoom(ZOOM_AMOUNT); 
    } 
    ViewCompat.postInvalidateOnAnimation(InteractiveLineGraphView.this); 
    return true; 
} 

縮放器只是一個輔助類保持當前的縮放級別

相關問題