android:操作滚动视图中包含的可见视图
我在 Scrollview 中有一个 TableLayout。表布局定义了一个表单,其各个行是文本视图、编辑文本或按钮。这些文本视图、编辑文本或按钮中的每一个的组合代表一个问题,该问题链接到特定类别。我有另一个列表,其中显示类别列表。当我选择一个类别时,我希望滚动视图显示以该特定类别开头的问题集。
实现此功能的问题是:滚动视图提供了一个方法scrollTo(int x, int y),使用它我可以在特定的x和y位置显示视图。实现此目的的最佳方法是什么:
1)确定添加到我的表格布局中的每个视图的确切高度(如何?),然后添加它们以获得以类别 2、3 开头的问题的起始 y 位置,4,……如果可以做到这一点,也许我可以将这个值传递给类别组选择监听器。
或者有更好的方法吗?
I have a TableLayout within a Scrollview. The Table layout defines a form, whose individual rows are text views, edittext or buttons. A combination of each of these text views, edittext or buttons represents a question, which is linked to a specific category. I have another list, which displays a list of the category. When I select a category, I want the scroll view to display the set of question that starts with that particular category.
The issue with implementing this functionality is: scroll view provides a method scrollTo (int x, int y), using which I can display the view at a particular x and y position. What is the best way to implement this:
1) determine the exact height of each view that is added to my table layout (how??) and then add them to get the starting y position of the question that starts with category 2, 3, 4, ...... If this can be done, perhaps I can pass on this value to the category group selection listener.
Or is there a better way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要测量所需滚动点之前的一个或多个子项,找到 y 轴的总和,然后滚动到那里。
measureChild()
You're going to want to measure the child or children before the desired scroll point, find the sum of y axis, and scroll there.
measureChild()