Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我image.scrollBy用来移动图像drawable。
image.scrollBy
然而,在调用之后image.getLeft()它image.getLayoutParams().leftMargin返回 0。
image.getLeft()
image.getLayoutParams().leftMargin
有任何想法吗?
我认为你调用image.getLayoutParams().leftMarginandimage.getLeft()进入构造函数或进入onCreate你的Activity!
onCreate
Activity
返回 0,因为您在对象初始化期间调用它!onCreate为了获得正确的值,您应该在外部和构造函数中调用它。
在构造函数期间,视图未初始化,并且如果参数为// ,onCreate则活动不知道视图的大小。wrap_contentfill_parentmatch_parent
wrap_content
fill_parent
match_parent
只有在视图初始化后才能使用获取大小方法。