Android set view position - setY vs setTop

I was going to move the button position programmatically. The button is in relative layout. I researched and found that we can use .setY()or .setTop(). Looks like they should work the same.

But in my case, it .setTop()does not change the position at all, but .setY()only works. I am not sure what I misunderstood, but it is very strange for me.

Is there anyone who can explain setY()vs setTop()correctly? What is the difference?

This is layout.xml:

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
       android:layout_width="match_parent"
       android:layout_height="40dp"
       android:layout_marginLeft="10dp"
       android:layout_marginRight="10dp"/>
</RelativeLayout>
+7
source share
2 answers

setY() setTop() , setY() , setTop() .

Android.

SetY()

. translationY y top.

SetTop()

.

+4

, setTop() setY(). , mTop layout(). mTop - .

0

Source: https://habr.com/ru/post/1656395/


All Articles