Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between getTop and getY

Tags:

android

views

I don't seem to understand the difference much between getTop() and getY() in android Views. How are they different ?

like image 583
Vihaan Verma Avatar asked May 22 '15 08:05

Vihaan Verma


1 Answers

getTop() returns the y coordinate relative to the parent.

getY() returns the y coordinate relative to the parent like getTop(), plus the y translation as returned by getTranslationY().

For questions like this it's often helpful to consult the source:

public final int getTop() {
    return mTop;
}

http://androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/view/View.java#10644

public float getY() {
    return mTop + getTranslationY();
}

http://androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/view/View.java#10908

like image 198
laalto Avatar answered Sep 22 '22 05:09

laalto