Android L中水波纹点击效果的实现

原文: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));
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值