有一个ScrollView,其中有许多子视图.有什么办法可以将每个孩子的offset-y移到ScrollView的顶部吗?
There is a ScrollView and which has many children views. Is there any way to get the offset-y to the top of the ScrollView for every child?
推荐答案嗯,不确定这是否是最快,最好的方法,但是如果您在屏幕上看到了视图的位置,并且知道ScrollView,您可以计算视图相对于ScrollView的偏移量.要获取视图在屏幕中的位置,请执行以下操作:
Hmmmm, not sure if this is the quickest, best way to do this, but if you get the view's location on screen, and you know the top of the ScrollView, you can calculate the offset of the view relative to the ScrollView. To get the position of a View in the screen:
int[] location = {0,0}; view.getLocationOnScreen(location);location[1]具有Y值.当视图位于视口上方"时,您将获得负值.
location[1] has the Y value. You will get negative values when the view is "above" the viewport.
更多推荐
如何获取ScrollView中视图的偏移量?
发布评论