获取控件四个角的位置

public static PointF getTopLeftCorner(View view) {
    float src[] = new float[8];
    float[] dst = new float[]{0, 0, view.getWidth(), 0, 0, view.getHeight(), view.getWidth(), view.getHeight()};
    view.getMatrix().mapPoints(src, dst);
    PointF cornerPoint = new PointF(view.getX() + src[0], view.getY() + src[1]);
    return cornerPoint;
}

public static PointF getTopRightCorner(View view) {
    float src[] = new float[8];
    float[] dst = new float[]{0, 0, view.getWidth(), 0, 0, view.getHeight(), view.getWidth(), view.getHeight()};
    view.getMatrix().mapPoints(src, dst);
    PointF cornerPoint = new PointF(view.getX() + src[2], view.getY() + src[3]);
    return cornerPoint;
}

public static PointF getBottomLeftCorner(View view) {
    float src[] = new float[8];
    float[] dst = new float[]{0, 0, view.getWidth(), 0, 0, view.getHeight(), view.getWidth(), view.getHeight()};
    view.getMatrix().mapPoints(src, dst);
    PointF cornerPoint = new PointF(view.getX() + src[4], view.getY() + src[5]);
    return cornerPoint;
}

public static PointF getBottomRightCorner(View view) {
    float src[] = new float[8];
    float[] dst = new float[]{0, 0, view.getWidth(), 0, 0, view.getHeight(), view.getWidth(), view.getHeight()};
    view.getMatrix().mapPoints(src, dst);
    PointF cornerPoint = new PointF(view.getX() + src[6], view.getY() + src[7]);
    return cornerPoint;
}

 

posted @ 2016-05-19 16:22  VichanHo  阅读(242)  评论(0编辑  收藏  举报