Created
November 11, 2013 08:35
-
-
Save ixiyang/7409825 to your computer and use it in GitHub Desktop.
自定义视图绘制边缘滑动的效果
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://developer.android.com/training/gestures/viewgroup.html | |
InteractiveChart | |
/** | |
* Draws the overscroll "glow" at the four edges of the chart region, if necessary. The edges | |
* of the chart region are stored in {@link #mContentRect}. | |
* | |
* @see EdgeEffectCompat | |
*/ | |
private void drawEdgeEffectsUnclipped(Canvas canvas) { | |
// The methods below rotate and translate the canvas as needed before drawing the glow, | |
// since EdgeEffectCompat always draws a top-glow at 0,0. | |
boolean needsInvalidate = false; | |
if (!mEdgeEffectTop.isFinished()) { | |
final int restoreCount = canvas.save(); | |
canvas.translate(mContentRect.left, mContentRect.top); | |
mEdgeEffectTop.setSize(mContentRect.width(), mContentRect.height()); | |
if (mEdgeEffectTop.draw(canvas)) { | |
needsInvalidate = true; | |
} | |
canvas.restoreToCount(restoreCount); | |
} | |
if (!mEdgeEffectBottom.isFinished()) { | |
final int restoreCount = canvas.save(); | |
canvas.translate(2 * mContentRect.left - mContentRect.right, mContentRect.bottom); | |
canvas.rotate(180, mContentRect.width(), 0); | |
mEdgeEffectBottom.setSize(mContentRect.width(), mContentRect.height()); | |
if (mEdgeEffectBottom.draw(canvas)) { | |
needsInvalidate = true; | |
} | |
canvas.restoreToCount(restoreCount); | |
} | |
if (!mEdgeEffectLeft.isFinished()) { | |
final int restoreCount = canvas.save(); | |
canvas.translate(mContentRect.left, mContentRect.bottom); | |
canvas.rotate(-90, 0, 0); | |
mEdgeEffectLeft.setSize(mContentRect.height(), mContentRect.width()); | |
if (mEdgeEffectLeft.draw(canvas)) { | |
needsInvalidate = true; | |
} | |
canvas.restoreToCount(restoreCount); | |
} | |
if (!mEdgeEffectRight.isFinished()) { | |
final int restoreCount = canvas.save(); | |
canvas.translate(mContentRect.right, mContentRect.top); | |
canvas.rotate(90, 0, 0); | |
mEdgeEffectRight.setSize(mContentRect.height(), mContentRect.width()); | |
if (mEdgeEffectRight.draw(canvas)) { | |
needsInvalidate = true; | |
} | |
canvas.restoreToCount(restoreCount); | |
} | |
if (needsInvalidate) { | |
ViewCompat.postInvalidateOnAnimation(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment