得到的视图位置相对于Android的最顶层的父 [英] get position of view with respect to top-most parent in android
问题描述
要获得视图相对于其父,我可以使用 getLeft()
, GetRight时()
,共达()
和 getBottom()
。但是,我怎么认为相对于最顶层的父布局文件的?
所以说,我前夕布局 RelativeLayout的
。然后说里面前夕,我有一些嵌套的布局。再深层次结构中我有一个看法的EditText。我如何获得的EditText视图的位置相对于前夜?
To get a view relative to its parent, I can use getLeft()
, getRight()
, getTop()
, and getBottom()
. But how do I get a view relative to the top-most parent of the layout file?
So say my eve layout is RelativeLayout
. Then say inside eve I have a number of nested layouts. And then deep within the hierarchy I have a EditText view. How do I get the location of the EditText view with respect to eve?
推荐答案
要找出绝对的视图位置,可以使用 view.getLocationOnScreen()
或 view.getLocationInWindow()
。
To find out absolute view location, you can use view.getLocationOnScreen()
or view.getLocationInWindow()
.
这篇关于得到的视图位置相对于Android的最顶层的父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!