get Point On View between root view and target view - Android User Interface

Android examples for User Interface:View Contains

Description

get Point On View between root view and target view

Demo Code


//package com.java2s;

import android.graphics.Point;
import android.view.View;

public class Main {

    public static Point getPointOnView(View root, View target) {
        final int[] l0 = new int[2];
        root.getLocationOnScreen(l0);//w  w  w . j a va2  s . c o  m

        final int[] l1 = new int[2];
        target.getLocationOnScreen(l1);

        l1[0] = l1[0] - l0[0] + target.getWidth() / 2;
        l1[1] = l1[1] - l0[1] + target.getHeight() / 2;

        return new Point(l1[0], l1[1]);
    }
}

Related Tutorials