检查android滚动视图是否可以滚动 [英] check if an android scrollview can scroll

查看:60
本文介绍了检查android滚动视图是否可以滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道是否可以知道Android Widget ScrollView 是否可以滚动?如果它有足够的空间,它就不需要滚动,但只要尺寸超过最大值,小部件就可以滚动.

Do you know if it is possible to know if an Android Widget ScrollView can scroll? If it has enough space it doesn't need to scroll, but as soon as a dimension exceeds a maximum value the widget can scroll.

我在参考资料中没有看到可以提供此信息的方法.也许可以对滚动视图内的线性布局的大小做一些事情?

I don't see in the reference a method who can give this information. Maybe is it possible to do something with the size of the linearlayout inside the scrollview?

推荐答案

我使用了以下受 https://stackoverflow 启发的代码.com/a/18574328/3439686 它有效!

I used the following code inspired by https://stackoverflow.com/a/18574328/3439686 and it works!

ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
int childHeight = ((LinearLayout)findViewById(R.id.scrollContent)).getHeight();
boolean isScrollable = scrollView.getHeight() < childHeight + scrollView.getPaddingTop() + scrollView.getPaddingBottom();

这篇关于检查android滚动视图是否可以滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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