//建立Scrollview类

public class MyScrollView extends ScrollView {

public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

}

//建立listview继承listview

package com.example.scrollview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;

public class Mylistview extends ListView {

int mLastMotionY;
    boolean bottomFlag;
    public Mylistview(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
        //对height重新赋值
        heightMeasureSpec= MeasureSpec.makeMeasureSpec(/*Integer.MAX_VALUE>> 2*/200,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    /*@Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // TODO Auto-generated method stub
        return true;
    }*/
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // TODO Auto-generated method stub
       
        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;
    }
}

//XML文件

//复制Scrollview类

<com.example.scrollview.MyScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".MainActivity" >

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
//复制listview类
        <com.example.scrollview.Mylistview
            android:id="@+id/lv"
            android:layout_width="match_parent"
            android:layout_height="100sp" >
        </com.example.scrollview.Mylistview>

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />

<Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="中国" />
    </LinearLayout>

</com.example.scrollview.MyScrollView>

Scrollview嵌套listview的更多相关文章

  1. 关于ScrollView嵌套ListView问题

    Android开发之ScrollView中嵌套ListView的解决方案   原文:http://blog.csdn.net/minimicall/article/details/40983331   ...

  2. 四种方案解决ScrollView嵌套ListView问题(转)

    以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...

  3. android 解决ScrollView嵌套ListView的问题,不能全屏,全屏不能显示下面控件

    在开发中遇到ScrollView嵌套ListView的问题,最开始发出不能全屏,效果是这样的: 但我想要的效果是这样的: 下面看一下布局文件: <?xml version="1.0&q ...

  4. ScrollView嵌套ListView的滑动冲突问题,是看大神的方法的,作为学习以后用的到

    在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollView嵌套ListView结 ...

  5. ScrollView嵌套ListView嵌套GridView的上下拉以及加载更多

    ScrollView 效果 ScrollView 说明 一个ScrollView 嵌套ListView 嵌套GridView的上拉加载更多,下拉刷新的demo. 主要是重写了GridView和Lsit ...

  6. 四种方案解决ScrollView嵌套ListView问题

    在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollView嵌套ListView结 ...

  7. 转:四种方案解决ScrollView嵌套ListView问题

    转载自:http://blog.sina.com.cn/s/blog_46798aa80101lxbk.html 原始的连接已经不知道是哪里了,项目中遇到了同样的问题,花了一下午都没有想到是嵌套引起的 ...

  8. 四种方案解决ScrollView嵌套ListView问题[转]

    http://bbs.anzhuo.cn/thread-982250-1-1.html 以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多 ...

  9. ScrollView嵌套ListView显示不完全、嵌套TextView不能滚动解决办法

    目录: 一.情景说明 二.最初做法 三.解决办法 一.情景说明 1.情景       最近项目刚好有一个需求,需要在一个界面中用ScrollView嵌套一个滚动的TextView和一个listView ...

  10. ScrollView嵌套ListView只显示一行

    错误描述 ScrollView嵌套ListView中导致ListView高度计算不正确,只显示一行. 解决方法 重写ListView的onMeasure方法,代码如下. @Override publi ...

随机推荐

  1. php 循环删除目录中的过期文件

            $savepath1 = 'Public/biaoqian/upload';         $path1 = dir($savepath1);           while (($ ...

  2. RN的像素及布局

    转自:http://www.cocoachina.com/ios/20150420/11608.html 宽度单位和像素密度 react的宽度不支持百分比,设置宽度时不需要带单位 {width: 10 ...

  3. javascript 在ie8中报“缺少标识符、字符串或数字“问题再现:

    开发和测试使用Chrome浏览器比较多,客户反馈某个页面打不开,自己用Chrome打开一切正常,用ie8打开,果然页面展现卡在那儿了,并且报了"缺少标识符.字符串或数字".查看是在 ...

  4. 【zz】Matlab 二值图像形态学函数 bwmorph

    原文地址:http://blog.sina.com.cn/wind8961 函数功能: 对二值图像进行数学形态学(Mathematical Morphology)运算. 语法格式: BW2 = bwm ...

  5. iOS开发:保持程序在后台长时间运行

    iOS开发:保持程序在后台长时间运行 2014 年 5 月 26 日 / NIVALXER / 0 COMMENTS iOS为了让设备尽量省电,减少不必要的开销,保持系统流畅,因而对后台机制采用墓碑式 ...

  6. Mac下手动安装SafariDriver extension

    环境:Mac OS X Yosemite 10.10.4下, Safari 8 Step 1:第一次运行SafariDriver时,先找到WebDriver extension的安装路径,比如/Use ...

  7. 新篇章,Golang 和 beego 初识

    beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API.Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado.sinatra ...

  8. jdk安装及环境变量配置

    JDK是 Java 语言的软件开发工具包,主要用于移动设备.嵌入式设备上的java应用程序.JDK是整个java开发的核心,它包含了JAVA的运行环境,JAVA工具和JAVA基础的类库. jdk下载地 ...

  9. Ubuntu 下使用declare的问题

    Ubuntu在shell的执行上用户root和普通用户是不一样的. 使用vi /etc/passwd 我们就可以看到在用户的最后一行也就是定义shell执行位置的地方root的位置是/bin/bash ...

  10. Elasticsearch学习之入门2

    关于Elasticsearch的几个概念: 1)在Elasticsearch中,文档归属于类型type,而类型归属于索引index,为了方便理解,可以把它们与传统关系型数据库做类比: Relation ...