//建立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. 抛弃msvcrtXX库

    对于极致要求体积的程序来说.抛弃Msvcrt里的函数是必要的.(尤其是msvcrtXX库)因为要使用mscvrt中的函数,就需要带上相对来 说,不能容忍的几kb的,vcrt初始化函数,包围在我们的Wi ...

  2. python登录执行命令

    #-*- coding: utf-8 -*- #!/usr/bin/python import paramiko import threading import getpass def ssh2(ip ...

  3. 常用OpenLDAP命令

    ldappasswd -x -D "cn=Manager,dc=clouderachina,dc=com" -W "uid=mis,ou=Group,dc=clouder ...

  4. Qt中2D绘图问题总结(一)----------基本的绘制与填充

    刚刚开始学习Qt不久,才开始渐渐地熟悉基础内容,学习过程中的一些知识的总结和感悟希望通过博客记录下来,与大家分享学习的同时,也是对自己坚持下去的鞭策,废话不多说了,开始第一次的小总结吧. Qt提供了强 ...

  5. 在Java filter中调用service层方法

    在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: public class WeiXinFilter implements Filter ...

  6. Java中获取长度length和size的问题

    1.length属性是针对Java中的数组来说的,要求数组的长度可以用其length属性: 2.length()方法是针对字符串来说的,要求一个字符串的长度就要用到它的length()方法: 3.ja ...

  7. 锋利的JQuery 学习笔记

    第一章                认识JQuery ·页面加载事件(可以写多个ready())$(document).ready(function(){alert(“hello world”);} ...

  8. 常用HTML标签元素结合及简介

    常用HTML标签元素结合及简介 <html></html> 创建一个HTML文档<head></head> 设置文档标题和其它在网页中不显示的信息< ...

  9. (翻译)Emacs Hooks

    Table of Contents 1. 51.2.2 Hooks 51.2.2 Hooks Hooks(钩子或挂钩,为了保持文章的纯正性,这种专有名词不做翻译,后续以hooks为主),是定制化Ema ...

  10. clip:rect矩形剪裁

    clip:rect(top right bottom left);依据上-右-下-左的顺序提供自图片左上角为(0,0)坐标计算的四个偏移数值,其中任一数值都可用auto替换. 矩形剪裁 还需要绝对定位 ...