栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何禁用和启用android ScrollView上的滚动?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何禁用和启用android ScrollView上的滚动?

试试这个

像这样创建您的CustomScrollview

import android.content.Context;import android.util.AttributeSet;import android.view.MotionEvent;import android.widget.ScrollView;public class CustomScrollView extends ScrollView {    private boolean enableScrolling = true;    public boolean isEnableScrolling() {        return enableScrolling;    }    public void setEnableScrolling(boolean enableScrolling) {        this.enableScrolling = enableScrolling;    }    public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    public CustomScrollView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public CustomScrollView(Context context) {        super(context);    }    @Override    public boolean onInterceptTouchEvent(MotionEvent ev) {        if (isEnableScrolling()) { return super.onInterceptTouchEvent(ev);        } else { return false;        }    }    @Override    public boolean onTouchEvent(MotionEvent ev) {       if (isEnableScrolling()) { return super.onTouchEvent(ev);       } else {return false;       }}}

在您的xml中

//“ com.example.demo”替换为您的包名称

<com.example.demo.CustomScrollView        android:id="@+id/myScroll"        android:layout_width="match_parent"        android:layout_height="wrap_content" >    </com.example.demo.CustomScrollView>

在您的活动中

CustomScrollView myScrollView = (CustomScrollView) findViewById(R.id.myScroll);        myScrollView.setEnableScrolling(false); // disable scrolling        myScrollView.setEnableScrolling(true); // enable scrolling


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/453000.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号