//建立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. 白皮 Chapter 2

    7.2 做题一遍就过的感觉简直太美好啦~然而我并没有测试数据QAQ //program name digit #include<cstdio> #include<iostream&g ...

  2. Get the current user permission level on a list item with ecmascript 分类: Sharepoint 2015-07-14 14:13 7人阅读 评论(0) 收藏

    To Check current users permissions using Ecmascript\Javascript client object model SharePoint 2010. ...

  3. The connection to adb is down, and a severe error has occured.问题解决方法小结

    遇到了几次这个问题:The connection to adb is down, and a severe error has occured. You must restart adb and Ec ...

  4. css初始化

    Css初始化代码: *{padding:0px;margin:0px;} body{font-size:12px;font-family: "宋体",Arial Black;tex ...

  5. web.xml中在Servlet中获取context-param和init-param内的参数

    引自:http://blog.csdn.net/yakson/article/details/9203231 web.xml里面可以定义两种参数:1.application范围内的参数,存放在serv ...

  6. Scala的下一步

    第七步:带类型的参数化数组 Scala里可以使用new实例化对象或类实例.当你在Scala里实例化对象,可以使用值和类型把它参数化:parameterize.参数化的意思是在你创建实例的时候“设置”它 ...

  7. 关于WebView的复习

    最近不知为啥,公司提出要用webView,偷笑不止.在青软上课的时候学过这东西,是说条件比较紧张的时候可以拿来充数的,现在公司里手机端开发人员很多,做的好好的,放着原生ui不用,非要赶时髦搞什么Web ...

  8. Java 社区论坛 - Sym 1.6.0 发布

    简介 Sym 是一个用 Java 写的现代化的社区论坛,欢迎来体验!(如果你需要搭建一个企业内网论坛,请使用 SymX) 非常详细的 Sym 功能点脑图 Sym 的诞生是有如下几点原因: (正版) 好 ...

  9. 微信Auth2.0授权的时候出现两次回调

    在获取用户OpenID的时候 $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".WX_APPID. ...

  10. IIS下注册COM组件(转)

    以Excel为例 问题描述: 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005基 ...