Return the position of childView relative to rootView . - Android User Interface

Android examples for User Interface:View Child

Description

Return the position of childView relative to rootView .

Demo Code

//package com.java2s;

import android.view.View;

public class Main {

    public static void getRelativeDrawPosition(View rootView,
            View childView, int[] outPosition) {
        assert outPosition.length == 2;
        outPosition[0] = 0;//from   w w  w.  j a v  a  2  s  . c  om
        outPosition[1] = 0;
        while (childView != null && childView != rootView) {
            outPosition[0] += childView.getX();
            outPosition[1] += childView.getY();
            childView = (View) childView.getParent();
        }
    }
}

Related Tutorials