Skip to content

Instantly share code, notes, and snippets.

@ixiyang
Created November 11, 2013 08:35
Show Gist options
  • Save ixiyang/7409825 to your computer and use it in GitHub Desktop.
Save ixiyang/7409825 to your computer and use it in GitHub Desktop.
自定义视图绘制边缘滑动的效果
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