gpt4 book ai didi

Android - offsetTopAndBottom 和 setTranslateY 的区别

转载 作者:可可西里 更新时间:2023-11-01 19:07:40 26 4
gpt4 key购买 nike

安卓View似乎有 2 种方法似乎执行一些非常相似的功能。

1] setTranslationX & setTranslationY
2] offsetLeftAndRightoffsetTopAndBottom

谁能告诉我它们有何不同?什么场景可以用[1]而不能用[2]?反之亦然?

最佳答案

offsetLeftAndRight()offsetTopAndBottom() 改变布局过程的结果,而 setTranslationX()setTranslationY 在布局结果的顶部添加一个额外的偏移量,默认值为 0。

一个后果是 leftAndRight/TopAndBottom 偏移量在每次布局传递时都会重置(例如,由 requestLayout() 触发),而翻译则不会。

我的理解是,offsetLeftAndRight()offsetTopAndBottom() 在您编写自己的 Layout 时最有用,而 setTranslationX()setTranslationY 是调整布局结果的通用方法。

关于Android - offsetTopAndBottom 和 setTranslateY 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33196553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com