Android:ScrollView 的总高度 [英] Android: Total height of ScrollView

查看:30
本文介绍了Android:ScrollView 的总高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的 ScrollView(扩展的 android.widget.ScrollView),我在我的布局中使用了它.我想测量此滚动视图内容的总高度.getHeight() 和 getMeasuredHeight() 没有给我正确的值(数字太高).

I have a custom ScrollView (extended android.widget.ScrollView) which I use in my layout. I want to measure the total height of the contents of this scrollview. getHeight() and getMeasuredHeight() don't give me correct values (too high numbers).

背景信息:我想确定用户滚动了多远.我使用 onScrollChanged 来获取 X 值,但我需要知道一个百分比,所以我需要滚动条的总高度.

Background information: I want to determine how far the user has scrolled. I use onScrollChanged to get the X value, but I need to know a percentage so I'll need the total scrollbar height.

非常感谢!埃里克

推荐答案

一个 ScrollView 总是有 1 个孩子.您需要做的就是获取孩子的身高以确定总身高:

A ScrollView always has 1 child. All you need to do is get the height of the child to determine the total height:

int totalHeight = scrollView.getChildAt(0).getHeight();

这篇关于Android:ScrollView 的总高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆