java视图位置怎么调整_java – Android设置视图位置 – setY vs setTop

我打算以编程方式移动按钮的位置.按钮处于相对布局中.我研究过并发现我们可以使用.setY()或.setTop().它们看起来应该是一样的.

但在我的情况下,.setTop()根本不会改变位置,而.setY()只能起作用.我不确定我做了什么误会,但对我来说这很奇怪.

有没有人可以正确解释setY()vs setTop()?

有什么不同?

这是layout.xml:

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="40dp"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"/>

最佳答案 setY()和setTop()之间的主要区别在于setY()设置视图相对于可视区域的顶部偏移量,而setTop()设置视图相对于其父级的顶部偏移量.

塞蒂()

Sets the visual y position of this view, in pixels. This is equivalent to setting the translationY property to be the difference between the y value passed in and the current top property.

机顶盒()

Sets the top position of this view relative to its parent.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值