- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
安卓View似乎有 2 种方法似乎执行一些非常相似的功能。
1] setTranslationX
& setTranslationY
2] offsetLeftAndRight
和 offsetTopAndBottom
谁能告诉我它们有何不同?什么场景可以用[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/
安卓View似乎有 2 种方法似乎执行一些非常相似的功能。 1] setTranslationX & setTranslationY 2] offsetLeftAndRight 和 offsetTop
当拖动 ImageView 时,我希望 ImageView 和 ListView 都垂直移动并停留在那里。下面是我的代码。起初,它似乎有效,但是当我上下滚动 ListView 时, ListView
我正在使用 CoordinatorLayout,其中 subview 位置使用 ViewCompat.offsetLeftAndRight 和 ViewCompact.offsetTopAndBott
我做了一个布局,它有两个 RelativeLayout,它们充当两个 slider (如状态栏上的通知),用户可以上下拖动,因此我必须更改顶部和底部文本值。
我是一名优秀的程序员,十分优秀!