关于ScrollView中嵌套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;
}
});

关于ScrollView中嵌套listview焦点滑动问题 解决的更多相关文章
- Android 如何在ScrollView中嵌套ListView
前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...
- Android实战技巧:如何在ScrollView中嵌套ListView
前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...
- Android -- 在ScrollView中嵌套ListView
在做一个工程,这个工程的布局可以相当的复杂,最外面是ScrollView,在ScrollView里面有两个Listview,这下好了,布局出来了,放在机子上跑,卡得想死有木有,信息乱跑乱出现,表示非常 ...
- ScrollView中嵌套ListView时,listview高度显示的问题
方法一:直接更改listview的控件高度,动态获取(根据条目和每个条目的高度获取) 前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个Lis ...
- ScrollView中嵌套ListView的问题
网上关于怎样在ScrollView中嵌套ListView的讨论有很多,我大概是搜索了一下,简单总结如下: 1.不要在ScrollView中嵌套ListView a.用一个LinearLayout来代替 ...
- ScrollView中嵌套ListView
scrollview中嵌入listview,要是直接把listview嵌进scrollview中,listview的高度是固定的不能进行滑动.默认情况下Android是禁止在ScrollView中放入 ...
- Android ScrollView中嵌套ListView
由于要做一个相似美团的团购产品.scrollview中还有嵌入listview,要是直接把listview嵌进scrollview中.listview的高度是固定的不能进行滑动.默认情况下Androi ...
- ScrollView中嵌套ListView显示
想要ScrollView中嵌套显示ListView 需要自定义ListView 并重写onMeasure方法 重新计算 heightMeasureSpec的高度 int newHeight = Me ...
- 解决ScrollView中嵌套ListView滚动效果冲突问题
在ScrollView中嵌套使用ListView,ListView只会显示一行到两行的数据.起初我以为是样式的问题,一直在对XML文件的样 式进行尝试性设置,但始终得不到想要的效果.后来在网上查了查, ...
随机推荐
- Quartzs -- Quartz.properties 配置
Quartzs -- Quartz.properties 配置 文件加载位置 默认:优先顺序 Classpath:quartz.properties --> org/quartz/quartz. ...
- asp.net中session的原理及应用
Session简介丶特性 1.Session是一种Web会话中的常用状态之一. 2.Session提供了一种把信息保存在服务器内存中的方式.他能储存任何数据类型,包含自定义对象. 3.每个客户端的Se ...
- Xcode编译错误和警告汇总<转>
1.error: macro names must be identifiers YourProject_prefix.pch 原因: 因为你弄脏了预处理器宏,在它处于<Multiple Val ...
- SQLServer User and Login Tips
use master IF EXISTS (SELECT * FROM sys.databases WHERE name = 'gpdb83sp')BEGIN DROP DATABASE gpdb83 ...
- docker-compose常用命令
--verbose:输出详细信息-f 制定一个非docker-compose.yml命名的yaml文件-p 设置一个项目名称(默认是directory名)docker-compose的动作包括:bui ...
- E: 软件包*需要重新安装,但是我无法找到相应的安装文件。(ubuntu14.04)
ubuntu安装搜狗输入法官方下载的安装包时,电脑有点卡我给强制关闭了,然后重启打开软件管理中心,直接闪退! 之后不能安装任何软件(包括命令). 显示: E: 软件包Sougou Pinyin需要重新 ...
- 详解OpenGL中的各种变换(投影变换,模型变换,视图变换)(完)——法线变换
前面两节内容已经说完了所有的三种变换.也就是说我们现在程序里面既不需要glLookAt(),也不需要gluPerspective(),这些矩阵我们都可以自己写.然后,再用glMultMatrix()来 ...
- ApplicationContext.xml文件详解
想必用过Spring的程序员们都有这样的感觉,Spring把逻辑层封装的太完美了(个人感觉View层封装的不是很好).以至于有的初学者都不知道Spring配置文件的意思,就拿来用了.所以今天我给大家详 ...
- 使用TextWatcher监听EditText变化
public class MainActivity extends AppCompatActivity { private TextView mTextView; private EditText m ...
- msvc库没有安装包,编译选项选择 代码生成 MT【多线程】,C#调用
参考提过的一个问题,封装VC++动态链接库,C#调用,并将C#程序打包为exe安装包. 感谢大神.