(第三种,第四种简单推荐使用)

在这里我要提出的是,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焦点滑动问题 解决的更多相关文章

  1. Android 如何在ScrollView中嵌套ListView

    前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...

  2. Android实战技巧:如何在ScrollView中嵌套ListView

    前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView.但刚开始的时候,会发现放入的小ListVie ...

  3. Android -- 在ScrollView中嵌套ListView

    在做一个工程,这个工程的布局可以相当的复杂,最外面是ScrollView,在ScrollView里面有两个Listview,这下好了,布局出来了,放在机子上跑,卡得想死有木有,信息乱跑乱出现,表示非常 ...

  4. ScrollView中嵌套ListView时,listview高度显示的问题

    方法一:直接更改listview的控件高度,动态获取(根据条目和每个条目的高度获取) 前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个Lis ...

  5. ScrollView中嵌套ListView的问题

    网上关于怎样在ScrollView中嵌套ListView的讨论有很多,我大概是搜索了一下,简单总结如下: 1.不要在ScrollView中嵌套ListView a.用一个LinearLayout来代替 ...

  6. ScrollView中嵌套ListView

    scrollview中嵌入listview,要是直接把listview嵌进scrollview中,listview的高度是固定的不能进行滑动.默认情况下Android是禁止在ScrollView中放入 ...

  7. Android ScrollView中嵌套ListView

    由于要做一个相似美团的团购产品.scrollview中还有嵌入listview,要是直接把listview嵌进scrollview中.listview的高度是固定的不能进行滑动.默认情况下Androi ...

  8. ScrollView中嵌套ListView显示

    想要ScrollView中嵌套显示ListView 需要自定义ListView 并重写onMeasure方法 重新计算  heightMeasureSpec的高度 int newHeight = Me ...

  9. 解决ScrollView中嵌套ListView滚动效果冲突问题

    在ScrollView中嵌套使用ListView,ListView只会显示一行到两行的数据.起初我以为是样式的问题,一直在对XML文件的样 式进行尝试性设置,但始终得不到想要的效果.后来在网上查了查, ...

随机推荐

  1. Java学习-006-三种数据库连接 MySQL、Oracle、sqlserver

    此文主要讲述在初学 Java 时,常用的三种数据库 MySQL.Oracle.sqlserver 连接的源代码整理.希望能对初学 Java 编程的亲们有所帮助.若有不足之处,敬请大神指正,不胜感激!源 ...

  2. 使用dd工具对磁盘RAID5和10进行I/O性能测试

    很多情况下大家在对于理论深信不疑,理论是有前提条件的,不是所有的情况下都是正确的.恰逢公司有服务器,故进行了磁盘性能测试,当然测试的结果也只是顺序I/O性能测试(dd机制决定的). 前提条件:(DEL ...

  3. 美团、点评、猫眼App下拉加载效果的源码分享

    今天我准备拿大众点评.美团.猫眼电影三款App的实例来分享一下APICloud下拉加载这个模块的效果. 美团App下拉加载效果   以美团中的下拉酷似动画的萌萌着小人儿效果作为参考,来实现的一个加载模 ...

  4. Android各个版本 版本号对应关系表

    Platform Version API Level VERSION_CODE Notes Android 5.0 21 LOLLIPOP Platform Highlights Android 4. ...

  5. Java 对象内存分配与回收

    JVM内存区域模型: * 程序计数器,内存区域极小,是当前线程的字节码执行行号指示器: * 虚拟机栈.本地方法栈,即平时所说的“栈”,是虚拟机用来执行方法(包括Java.非Java方法)时,使用的临时 ...

  6. 用仿ActionScript的语法来编写html5——第八篇,图片处理+粒子效果

    用仿ActionScript的语法来编写html5系列开发到现在,应该可以做出一些东西了,下面先来研究下图片的各种效果预览各种效果看下图效果和代码看这里,看不到效果的请下载支持html5的浏览器 ht ...

  7. UISwitch属性

    1.onTintColor 处于on时switch 的颜色     switchImage.onTintColor = [UIColor grayColor]; 2.tintColor 处于off时s ...

  8. ios-消息弹框之UIAlertView, UIActionSheet以及UIAlertController小结

    首先storyboard中创建对应按钮并拖线,来演示不同的效果 首先点击了actionSheet按钮效果如图 实现弹框需要遵守设置代理,遵守协议. 效果就是从底部向上弹起来的框框. 通过对按钮的点击输 ...

  9. 线性空间光照(即Gamma)

    在渲染管线中正确使用Gamma校正是决定渲染效果的一个非常重要的因素,现在商业引擎包括很多国内引擎都已经是在线性空间计算光照.当然也包括我们之前公司设计的引擎.关于gamma校正的定义可以查看wiki ...

  10. 在Android平台下的基于Linux-C 的测试程序

    iTOP-4412 开发板可以运行的文件系统很多,在具体的文件系统上实现特定功能前,可以 使用Linux-C 程序来测试硬件以及驱动.而且这些程序很容易移植到Android.Qt/E 以及最小文件系统 ...