Android Studio - 如何停止ScrollView回到顶部
创始人
2024-08-16 01:30:15
0

要停止ScrollView回到顶部,可以使用以下代码示例中的方法:

  1. 在XML布局文件中,将ScrollView替换为自定义的ScrollView子类,例如NoScrollScrollView:


    


  1. 创建NoScrollScrollView类,并继承自ScrollView:
public class NoScrollScrollView extends ScrollView {

    public NoScrollScrollView(Context context) {
        super(context);
    }

    public NoScrollScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoScrollScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }
}
  1. 通过将onTouchEvent和onInterceptTouchEvent方法的返回值设置为false,禁用ScrollView的滚动功能。

这样,当ScrollView被滚动时,它将不会回到顶部。

相关内容

热门资讯

sohoo开挂辅助!德州私人局... sohoo开挂辅助!德州私人局怎么透视(透视)插件-好像关于是真的挂1、sohoo开挂辅助!德州私人...
透视推荐!拱趴大菠萝挂怎么安装... 透视推荐!拱趴大菠萝挂怎么安装(透视)wepoker免费透视脚本,教程操作(真的有挂)-哔哩哔哩1、...
wepoker有人用过吗!we... wepoker有人用过吗!wepoker透视辅助(透视)工具-切实详情存在有挂1、点击下载安装,we...
透视曝光!poker worl... 透视曝光!poker world辅助器(透视)hhpoker有没有透视辅助,教程方式(有挂方针)-哔...
wejoker辅助脚本!德州h... wejoker辅助脚本!德州hhpoker是真的吗(透视)教程-都是关于存在有挂1、完成德州hhpo...
透视解密!wpk德州局透视(透... 透视解密!wpk德州局透视(透视)wepoker怎么开辅助,教程指南(果真有挂)-哔哩哔哩wepok...
透视科普!hhpoker可以开... 透视科普!hhpoker可以开挂吗(透视)hhpoker可以控制牌吗,教程秘籍(有挂教程)-哔哩哔哩...
德州局透视!hhpoker德州... 德州局透视!hhpoker德州牛仔视频(透视)技巧-总是推荐真的是有挂hhpoker德州牛仔视频是不...
透视教你!hhpoker透视码... 透视教你!hhpoker透视码怎么用(透视)hhpoker软件可以玩吗,教程手筋(有挂讲解)-哔哩哔...
hhpoker德州透视挂!hh... hhpoker德州透视挂!hhpoker有后台操控吗(透视)攻略-都是关于存在有挂进入游戏-大厅左侧...