get Relative Location between two views - Android android.view

Android examples for android.view:View

Description

get Relative Location between two views

Demo Code

import android.view.View;

public class Main {

  private static int sLocation[] = new int[2];

  public static int[] getRelativeLocation(View reference, View view) {
    reference.getLocationInWindow(sLocation);
    int referenceX = sLocation[0];
    int referenceY = sLocation[1];
    view.getLocationInWindow(sLocation);
    sLocation[0] -= referenceX;//from   w w w.j  ava 2  s. co  m
    sLocation[1] -= referenceY;
    return sLocation;
  }

}

Related Tutorials