animation view click

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:33   1775   0
 private boolean containPoint(View view, float x, float y) {
        Rect rect = new Rect();
        view.getHitRect(rect);
        
        Transformation trans = new Transformation();
        Animation anim = view.getAnimation();
        anim.getTransformation(view.getDrawingTime(), trans);
        
        float dx = view.getLeft();
        float dy = view.getTop();
        Matrix matTranslate = new Matrix();
        matTranslate.postTranslate(dx, dy);
        
        Matrix matrix = trans.getMatrix();
        matrix.postConcat(matTranslate);
        
        // 求逆矩阵
        Matrix mat = new Matrix();
        if (matrix.invert(mat)) {
            float[] pointsSrc = new float[] { x, y };
            float[] pointsEnd = new float[] { 0, 0 };
            
            // Get the point in inverted matrix.
            mat.mapPoints(pointsEnd, pointsSrc);
            // Offset the point because we translate matrix which dx and dy before.
            x = pointsEnd[0] + dx;
            y = pointsEnd[1] + dy;
            x = (int)pointsEnd[0] + (int)dx;
            y = (int)pointsEnd[1] + (int)dy;
        }
        
        return rect.contains((int)x, (int)y);
    }
    
    protected Rect mapRect(Matrix matrix, Rect srcRect) {
        float[] values = new float[9];
        matrix.getValues(values);
        float scaleX = values[0];
        float scaleY = values[4];
        float left = srcRect.left + srcRect.width() * (1 - scaleX) / 2;
        float top = srcRect.top + srcRect.height() * (1 - scaleY) / 2;
        float right = srcRect.top - srcRect.width() * (1 - scaleX) / 2;
        float bottom = srcRect.bottom - srcRect.height() * (1 - scaleY) / 2;
        
        Rect rect = new Rect((int)left, (int)top, (int)right, (int)bottom);
        return rect;
    }


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP