关于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文件的样 式进行尝试性设置,但始终得不到想要的效果.后来在网上查了查, ...
随机推荐
- 人脸识别的ppt
http://wenku.baidu.com/link?url=GWiNRy_9mzqBZ9_2DDZbHRZbBbaBofhs1Y0pBS7aiE5oab8TY78r_z6aAlqo_L9AZzD4 ...
- python format
python自2.6后,新增了一种格式化字符串函数str.format(),威力十足,可以替换掉原来的% 注:以下操作版本是python2.7 映射示例 语法 通过{} 和 : 替换 % 通过位置 ...
- 图像处理之泛洪填充算法(Flood Fill Algorithm)
泛洪填充算法(Flood Fill Algorithm) 泛洪填充算法又称洪水填充算法是在很多图形绘制软件中常用的填充算法,最熟悉不过就是 windows paint的油漆桶功能.算法的原理很简单,就 ...
- NSString的截取
// // main.m // 02-字符串的获取 // // Created by apple on 14-3-20. // Copyright (c) 2014年 apple. All r ...
- (转)在PHP语言中使用JSON
原文 : http://www.ruanyifeng.com/blog/2011/01/json_in_php.html --------------------------------------- ...
- crsctl stat res -t 和 crsctl stat res -init -t
11.2.0.2的grid infrastructure中crsctl stat res命令不再显示如ora.cssd.ora.ctssd.ora.diskmon等基础资源的信息.但是查看这些基础资源 ...
- tcpdump note
from http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html 用简单的话来定义tcpdump,就是:dump the tr ...
- Leetcode: Create Maximum Number
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...
- PHP-字符串过长不用担心
字符串过长可以用定界符: >>>GOD ................巨长务必的字符串 GOD;
- ios json parse
参考:http://wenxin2009.iteye.com/blog/1671691