calculate Delta between two View - Android User Interface

Android examples for User Interface:View

Description

calculate Delta between two View

Demo Code


//package com.java2s;

import android.view.View;

public class Main {
    public static int[] calculateDelta(View first, View second) {
        final int[] sourceLocation = new int[2];
        first.getLocationOnScreen(sourceLocation);

        final int[] currentNameLocation = new int[2];
        second.getLocationOnScreen(currentNameLocation);

        final int[] delta = new int[2];
        delta[0] = currentNameLocation[0] - sourceLocation[0]
                + second.getPaddingLeft() - first.getPaddingLeft();
        delta[1] = currentNameLocation[1] - sourceLocation[1]
                + second.getPaddingTop() - first.getPaddingTop();

        return delta;
    }//from w  w  w.  ja v a  2s. co m
}

Related Tutorials