ScrollView 设置滚动是否可用
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 设置滚动是否可用的更多相关文章
- 触摸点为scrollview上的子控件时,scrollview不能滚动(iOS8)
现象:在iOS8上,scrollview上面布局了多行多列的button,滑动scrollview,如果当触摸点是在按钮上,scrollview不能滚动. 例如: 解决方法:设置scrollview的 ...
- 小程序给scroll-view设置高度,使得它能适配各种尺寸的手机
scroll-view占满整个屏幕,且scroll-view的滚动不影响到页面其他地方的滚动 在iphone6的尺寸下,scroll-view设置高度为1110rpx,就不会影响页面其他地方的滚动 但 ...
- ScrollView垂直滚动控件
ScrollView垂直滚动控件 一.简介 二.方法 1)ScrollView垂直滚动控件使用方法 1.在layout布局文件的最外层建立一个ScrollView控件 2.在ScrollView控件中 ...
- 完美解决EditText和ScrollView的滚动冲突(上)
在网上搜了一下EditText和ScrollView的滚动冲突,发现差点儿全部的解决方式都是触摸EditText的时候就将事件交由EditText处理,否则才将事件交由ScrollView处理.这样确 ...
- 解决scrollview不滚动
scrollView不滚动的时候 试试这个,有时候药到病除:
- Lodop窗口的按钮、权限,隐藏或设置功能不可用
Lodop隐藏某个按钮或部分,具体参考Lodop技术手册 SET_SHOW_MODE篇.以下是几个例子,(对应下图图片): 第一种:LODOP.SET_SHOW_MODE ("HIDE_PB ...
- 封装scrollView 循环滚动,tableViewCell(连载) mvc
封装 封装 封装 ... 封装的重要性太重要了 给大家在送点干货 从一个项目中抽取出来的.和大家一起分享 封装scrollView 循环滚动.tableViewCell(连载) 明天还会更新 tabl ...
- 监视scrollview是否滚动到底
//监视scrollview是否滚动到底 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [refreshHeaderViewegoRe ...
- 屏蔽scrollview的滚动
外层有scrollview时,手指移动方向跟滚动条方向相同时,会导致scrollview的滚动.此时如果不想滚动的话,可以在要接受ontouch的子视图,或者子子视图中的touch监听里加上v.get ...
随机推荐
- mac安装IDEA
Mac上安装Java7 首先我们需要去oracle下载最新的jdk,笔者拿到的最新的版本是1.7.0_45-b18,这里没有什么好说的,直接下载安装即可,安装完毕后需要在.bash_profile或者 ...
- 关于Cocos2d-x中掉帧导致游戏一卡一卡的网上一些的解决方法
方法1 掉帧主要是setpostion引起的 因为每一帧每一个精灵都要set一次虽然不知道为什么会这样但是if(poX<1000&&pox>-100){ xx-& ...
- Java 经典问题
九种基本类型及封装类 基本类型 boolean byte char short int long double void 二进制位数 1 8(一字节) 16(2字节) 16(2字节) 32(4字节) ...
- 【转】 PreTranslateMessage作用和使用方法
PreTranslateMessage作用和使用方法 PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗口的消息都要通过这里,比较常用, ...
- 第三百一十七节,Django框架,缓存
第三百一十七节,Django框架,缓存 由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存,缓存将一个某个views的返 ...
- pyqt的setObjectName()/findChild()
根据设置的Name标示查找组件的对象,关键函数:setObjectName()/findChild() findChild()/2:需要两个参数, 参数一:组件的类型,如QLineEdit.QPush ...
- Perl Spreadsheet::WriteExcel 模块自动生成excel 文件
Spreadsheet::WriteExcel 是一个跨平台的生成excel文件的模块, 可以方便的设置单元格内容, 样式, sheet 的名称: 但是默认情况下中文会乱码, 需要用Encode模块进 ...
- 一些 Linux 常用命令说明
目前由于自己接触到的是 Windows 的操作系统,所以会经常使用 git bash 来提交代码到 github上. git bash 是 Windows 下模拟 Linux 的命令行工具. 在此总结 ...
- 【Java面试题】18 java中数组有没有length()方法?string没有lenght()方法?下面这条语句一共创建了多少个对象:String s="a"+"b"+"c"+"d";
数组没有length()这个方法,有length的属性.String有有length()这个方法. int a[]; a.length;//返回a的长度 String s; s.length();// ...
- preventDefault
e.preventDefault()阻止事件默认行为 例如: $("a").click(function (e) { alert("默认行为被禁止喽"); ...