//建立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. 三、Python 变量、运算符、表达式

    3.1 变量 变量是计算机内存中的一块区域,变量可以存储规定范围内的值,值可以改变,其实是将值在内存中保存地址位交给变量,变量去内存中获取,重新赋值,改变的就是内存地址位. 命名: 变量名由字母.数字 ...

  2. React之Froms

    In React, a <textarea> uses a value attribute instead. This way, a form using a <textarea&g ...

  3. C#_基础

    1.形参与实参 形参是函数定义时的参数,实参是函数被引用时传给它的参数 2.重载与重写 重载:发生在同一个类中,函数(方法)名相同但参数列表必须不同,返回类型可以不同 重写:发生在继承类之间,子类必须 ...

  4. Java 设计模式学习

    看完headfirst设计模式,简单总结一下. 写在最前面:设计模式的关心的问题为"弹性.易于维护.易于扩展",通过对模式的应用,让自己的代码能够得到良好的可塑性.但是个人认为不能 ...

  5. Longest Substring Without Repeating Characters(Difficulty: Medium)

    题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...

  6. JavaScript控制类名(className属性)

    语法:object.className =classname   (注意大小写) 作用:获取元素的class属性,为网页内的某个元素指定一个CSS样式来更改该元素的外观 示例: <!DOCTYP ...

  7. Spring Security 从配置入门 学习讲解。万恶之源------------web.xml

    这段时间,工作闲了下来,接触了Spring Security,对于我一个基础很差的人来说,无疑是个挑战啊. 经过一段时间的摸索,终于有了点眉目,在这里,要特别感谢http://blog.csdn.ne ...

  8. IOS managerTime

    1. NSString ->NSdate NSString *birthday =  self.btnBirthday.titleLabel.text; NSDateFormatter *dat ...

  9. 亲身试用python简单小爬虫

    前几天基友分享了一个贴吧网页,有很多漂亮的图片,想到前段时间学习的python简单爬虫,刚好可以实践一下. 以下是网上很容易搜到的一种方法: #coding=utf-8 import urllib i ...

  10. JQuery的一些简单操作01

    一.JQuery的隐藏和显示效果 1.hide/show/toggle hide隐藏效果,hide(1000)括号里面跟毫秒,show显示效果同样后面括号可以有数值,toggle开关按钮,交替作用隐藏 ...