如何获取ScrollView中视图的偏移量?

编程入门 行业动态 更新时间:2024-10-24 18:19:07
本文介绍了如何获取ScrollView中视图的偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有一个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中视图的偏移量?

本文发布于:2023-10-18 12:51:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   偏移量   ScrollView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!