extends:http://stackoverflow.com/questions/5763304/disable-scrollview-programmatically , http://stackoverflow.com/questions/18893198/how-to-disable-and-enable-the-scrolling-on-android-scrollview

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView; public class LockableScrollView extends ScrollView { // true if we can scroll (not locked)
// false if we cannot scroll (locked)
private boolean mScrollable = true; public LockableScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} public LockableScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
} public LockableScrollView(Context context) {
super(context);
} public void setScrollingEnabled(boolean enabled) {
mScrollable = enabled;
} public boolean isScrollable() {
return mScrollable;
} @Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// if we can scroll pass the event to the superclass
if (mScrollable) return super.onTouchEvent(ev);
// only continue to handle the touch event if scrolling enabled
return mScrollable; // mScrollable is always false at this point
default:
return super.onTouchEvent(ev);
}
} @Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Don't do anything with intercepted touch events if
// we are not scrollable
if (!mScrollable) return false;
else return super.onInterceptTouchEvent(ev);
} }
// "com.example.demo" replace with your packagename

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

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

ScrollView 设置滚动是否可用的更多相关文章

  1. 触摸点为scrollview上的子控件时,scrollview不能滚动(iOS8)

    现象:在iOS8上,scrollview上面布局了多行多列的button,滑动scrollview,如果当触摸点是在按钮上,scrollview不能滚动. 例如: 解决方法:设置scrollview的 ...

  2. 小程序给scroll-view设置高度,使得它能适配各种尺寸的手机

    scroll-view占满整个屏幕,且scroll-view的滚动不影响到页面其他地方的滚动 在iphone6的尺寸下,scroll-view设置高度为1110rpx,就不会影响页面其他地方的滚动 但 ...

  3. ScrollView垂直滚动控件

    ScrollView垂直滚动控件 一.简介 二.方法 1)ScrollView垂直滚动控件使用方法 1.在layout布局文件的最外层建立一个ScrollView控件 2.在ScrollView控件中 ...

  4. 完美解决EditText和ScrollView的滚动冲突(上)

    在网上搜了一下EditText和ScrollView的滚动冲突,发现差点儿全部的解决方式都是触摸EditText的时候就将事件交由EditText处理,否则才将事件交由ScrollView处理.这样确 ...

  5. 解决scrollview不滚动

    scrollView不滚动的时候 试试这个,有时候药到病除:

  6. Lodop窗口的按钮、权限,隐藏或设置功能不可用

    Lodop隐藏某个按钮或部分,具体参考Lodop技术手册 SET_SHOW_MODE篇.以下是几个例子,(对应下图图片): 第一种:LODOP.SET_SHOW_MODE ("HIDE_PB ...

  7. 封装scrollView 循环滚动,tableViewCell(连载) mvc

    封装 封装 封装 ... 封装的重要性太重要了 给大家在送点干货 从一个项目中抽取出来的.和大家一起分享 封装scrollView 循环滚动.tableViewCell(连载) 明天还会更新 tabl ...

  8. 监视scrollview是否滚动到底

    //监视scrollview是否滚动到底 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [refreshHeaderViewegoRe ...

  9. 屏蔽scrollview的滚动

    外层有scrollview时,手指移动方向跟滚动条方向相同时,会导致scrollview的滚动.此时如果不想滚动的话,可以在要接受ontouch的子视图,或者子子视图中的touch监听里加上v.get ...

随机推荐

  1. axis client error Bad envelope tag: definitions

    http://blog.csdn.net/lifuxiangcaohui/article/details/8090503 ——————————————————————————————————————— ...

  2. (转)SDL2.0在mfc窗口中显示yuv的一种方法

    DWORD ThreadFun() {    //用mfc窗口句柄创建一个sdl window    SDL_Window * pWindow = SDL_CreateWindowFrom( (voi ...

  3. CentOS简单命令学习:date cal bc

    简单的shell指令: 1.日期的格式化显示: 2.日历的显示: 3.bc计算器: 使用Tab指令自动补全:

  4. WordCount 远程集群源码

    package test; import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop ...

  5. hadoop2.7.1单机和伪集群的搭建-0

    内容中包含 base64string 图片造成字符过多,拒绝显示

  6. 【Deep learning】NLP

    http://www.tuicool.com/articles/EvaQJnJ http://cs224d.stanford.edu/syllabus.html

  7. 一篇文看懂Hadoop

    我们很荣幸能够见证Hadoop十年从无到有,再到称王.感动于技术的日新月异时,希望通过这篇内容深入解读Hadoop的昨天.今天和明天,憧憬下一个十年. 本文分为技术篇.产业篇.应用篇.展望篇四部分 技 ...

  8. 理解BSTR数据类型 神奇的BSTR

    理解BSTR数据类型 神奇的BSTR - 深蓝的日志 - 网易博客 http://blog.163.com/pugood@126/blog/static/13441759320091111115264 ...

  9. select2 选择框插件

    <select id="selBusi_type"><select> //初始化业务类型下拉 var initBusiTypeSel = function( ...

  10. 第四章 Spring.Net 如何管理您的类___让对象了解自己的容器

    我们在开发中,经常需要让对象了解自己所在的容器的信息,例如,有时我们需要让对象知道,对象所在容器的引用是什么,或者是对象在容器中的名称是什么 .Spring.Net 中提供了两个接口,我们使用这两个接 ...