android - 为什么 Android ScrollView 在它的 child 的高度小于屏幕时调用 onScrollChanged()?

标签 android android-layout android-ui android-scrollview

我有一个 ScrollView,它的唯一子元素是 RelativeLayout。 最近我注意到这个方法:

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {}

即使在子高度小于 ScrollView 高度时也会被调用,如下所示:

this 指的是我的 ScrollView,rl 指的是 RelativeLayout

这是正常行为还是我遗漏了什么?

编辑: 我经常在 RelativeLayout 中添加和删除 View ,因此每次都禁用滚动/触摸等似乎不是一个好的解决方案。

我目前的修复是检查滚动是否真的改变了什么,如果没有,我就忽略它:

    // in case no actual scroll has occurred - just return.
    if (t == oldt && l == oldl) {
        return;
    }

最佳答案

这是正常现象

如果你想停止 ScrollView 滚动那​​么你必须试试这个

scroll.setEnabled(false); 
scroll.setFocusable(false); 
scroll.setHorizontalScrollBarEnabled(false); 
scroll.setVerticalScrollBarEnabled(false);

希望这能奏效

关于android - 为什么 Android ScrollView 在它的 child 的高度小于屏幕时调用 onScrollChanged()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15107283/

相关文章:

android - 如何将 Google Map Api 安装到我的新 Android 设备上?

android - 编辑文本 : How to show cursor and hide underline at a time?

Android 在按住 ImageButton 时在布局之间滑动

Android RatingBar - 一团糟

android - 如何防止一个 fragment 被多次添加?

android - 如何像这样注入(inject)网络模块?

android - OPC UA 支持 QT 移动

android - 设计在 Android Studio 预览中完美显示但在真实设备中不显示

android - 如何将一个元素对齐到相对布局中另一个元素的中心和上方?

java - 是否可以在 Swing 应用程序中使用 android UI 组件?