What I want to do is, to draw a line from the edge of a button to a point on the screen...
I\'m using a dialog fragment for this... And all functions I tried always
You need to wait for the callback when the layout has placed the children views. The code you are using returns 0 because the position is returned before the layout is placed. Use this code:
YourView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
int[] locations = new int[2];
YourView.getLocationOnScreen(locations);
int x = locations[0];
int y = locations[1];
}
});