原文:http://blog.csdn.net/singwhatiwanna/article/details/42614953
看到这篇大神的指导后,按着博文把代码实现了效果。
然后又紧接着看了大神的第二遍博文:android学习路线:如何成长为高级工程师
突然想跟着这位大神的步伐走,所以开了博客,写这篇博文,纯属转载。
决定学习大神的高阶进阶方法,多多写博客,记录并总结所学知识,,希望能快速提高自己,最终达到大神境界。
本来想直接运行博客中的代码,但是加不了大神博主的群,拿不到源码,所以自己补充了,欠缺的代码部分。
private static final int INVALIDATE_DURATION = 100; private View mTouchTarget; private boolean mIsPressed; private int mCenterX, mCenterY; private int mTargetWidth = 0; private boolean mShouldDoAnimation; private int mMinBetweenWidthAndHeight; private int mRevealRadius; private int mRevealRadiusGap = 15; private int mMaxRevealRadius; private int[] mLocationInScreen = new int[2]; private Paint mPaint;
mPaint = new Paint(); mPaint.setColor(0x66888888);
//初始化效果开始的数据 private void initParametersForChild(MotionEvent event, View view) { mCenterX = (int) event.getX(); mCenterY = (int) event.getY(); mTargetWidth = view.getMeasuredWidth(); mShouldDoAnimation = true; mMinBetweenWidthAndHeight = Math.min(view.getMeasuredWidth(), view.getMeasuredHeight()); mMaxRevealRadius = getMaxRevealRadius(event, view); mRevealRadius = 0; getLocationOnScreen(mLocationInScreen); } //获取最大半径 private int getMaxRevealRadius(MotionEvent event, View view) { Point centerP = new Point((int) event.getX(), (int) event.getY()); Point ltP = new Point(0, 0); Point lbP = new Point(0, view.getMeasuredHeight()); Point trP = new Point(view.getMeasuredWidth(), 0); Point tbP = new Point(view.getMeasuredWidth(), view.getMeasuredHeight()); int length = Math.max(Math.max(centerP.betweenlength(ltP), centerP.betweenlength(lbP)), Math.max(centerP.betweenlength(trP), centerP.betweenlength(tbP))); return length; } class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; } //两点之间的距离 public int betweenlength(Point other) { return (int) Math.sqrt(Math.pow((x - other.x), 2) + Math.pow((y - other.y), 2)); } }