关于ScrollView中嵌套listview焦点滑动问题 解决
2016-04-14 14:39
459 查看
(第三种,第四种简单推荐使用)
在这里我要提出的是,listview能滚动的前提是:当listview本身的高度小于listview里的子view。
第一种方法
只需在MainActivity中 找到listview 和 scrollview
然后给listview设置监听事件
第二种方法
只需重写listview即可
第三种方法
只需重写listview即可
第四种方法
只需在MainActivity中 找到listview
然后给listview设置监听事件
在这里我要提出的是,listview能滚动的前提是:当listview本身的高度小于listview里的子view。
第一种方法
只需在MainActivity中 找到listview 和 scrollview
然后给listview设置监听事件
listView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(event.getAction() == MotionEvent.ACTION_UP){ scrollView.requestDisallowInterceptTouchEvent(false); }else{ scrollView.requestDisallowInterceptTouchEvent(true); } return false; } });
第二种方法
只需重写listview即可
package com.bawei.day06; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.widget.ListView; public class ListViewForScrollView extends ListView { int mLastMotionY; boolean bottomFlag; public ListViewForScrollView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (bottomFlag) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub int y = (int) ev.getRawY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastMotionY = y; break; case MotionEvent.ACTION_MOVE: int deltaY = y - mLastMotionY; if (deltaY < 0) { View child = getChildAt(0); if (child != null) { if (getLastVisiblePosition() == (getChildCount()-1) && child.getBottom() == (getChildCount()-1)) { bottomFlag = true; getParent().requestDisallowInterceptTouchEvent(true); } int bottom = child.getBottom(); int padding = getPaddingTop(); if (getLastVisiblePosition() == (getChildCount()-1) && Math.abs(bottom - padding) >= 20) { bottomFlag = true; getParent().requestDisallowInterceptTouchEvent(true); } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: break; } return super.onTouchEvent(ev); } public void setBottomFlag(boolean flag) { bottomFlag = flag; } }
第三种方法
只需重写listview即可
package com.bawei.day06; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.widget.ListView; public class ListViewForScrollView extends ListView { int mLastMotionY; boolean bottomFlag; public ListViewForScrollView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override public boolean dispatchTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub getParent().requestDisallowInterceptTouchEvent(true); return super.dispatchTouchEvent(ev); } }
第四种方法
只需在MainActivity中 找到listview
然后给listview设置监听事件
listView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub listView.getParent().requestDisallowInterceptTouchEvent(true); return false; } });
相关文章推荐
- 进入BIOS SHELL DUMP 命令
- Android 自定义View高级特效,神奇的贝塞尔曲线
- Ubuntu系统操作笔记
- JavaScirpt之JQuery库入门篇
- VS中修改.net版本
- python mongoengine
- Android中Listview实现分页加载效果OnScrollListener
- 虚拟机Ubuntu Server(宿主Win7)ftp服务的安装与启动
- windows下使用命令行运行PHP
- Ubuntu ctrl+alt+F1~F6黑屏
- FTP客户端(利用sun.net.ftp.FtpClient实现)
- linux 查看文件系统类型
- Linux进程间通信——使用共享内存
- mysql中文乱码问题
- 在window弄的php项目发布到linux的编码问题
- js前台实现上传图片的预览
- json
- C++ char * char string 转换
- 【8】mysql数据控制语言DCL(Data Control Language)
- unreal3之FName及潜在bug