//建立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. Single-page app(SPA)

    有哪些值得推荐的一页式网站(Single-page app)? http://pro.weltrade.com/en/ 最近开到一下国外网站,一页到底,感觉很高大上,到底是怎么做出来的呢?技术要点是什 ...

  2. ASP.NET4.5从零开始(1)

    使用Web窗体 引言 前段时间客户A突然提出,B项目希望可以做成BS形式的,之前是CS的,因为我之前也没学过ASP.NET,于是一边百度,一边Coding,马马虎虎的把功能流程给调通,然后就交差了,想 ...

  3. 用PowerMock mock final类constructors

    也相对简单,直接贴代码 被测方法 public class EmployeeServiceWithParam { public void createEmployee(final Employee e ...

  4. google closure--继承模块一:goog.inherits()

    最近在项目是使用了google closure框架,深入研究了一下源码,先从最简单的继承系统吧. 废话不多说,closure继承模块主要有2个API: goog.inherits(childCtor, ...

  5. Android Activity中获取当前焦点的控件,自动化输入EditText

    获取焦点的view对象 View view=getWindow().getDecorView().findFocus(); 如果是EditText if(view instanceof EditTex ...

  6. IOS 设置导航栏

    //设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...

  7. Discuz插件开发中的困惑

    1.关于缓存 这几天一直纠结于Discuz的缓存问题,今天终于有点小发现:首先Discuz的缓存可以通过数据库.文件等方式进行!在Discuz的配置文件config_global.php中有一个配置项 ...

  8. eclipse中如何打jar包

    在eclipse中写个小测试程序(需要用到第三方jar文件),打成jar文件,然后到linux下执行做测试,查了很多资料也没有说怎么把第三方jar打入jar,使用ant,又太麻烦. 1   选择Mai ...

  9. 微软Face API体验——人脸检测

    微软推出了全新REST API,现在可免费获取密钥,大家可以赶快申请!申请地址:https://cn.projectoxford.ai/subscription 看了网站的API介绍,忍不住赶快体验一 ...

  10. 用nodejs实现json和jsonp服务

    一.JSON和JSONP JSONP的全称是JSON with Padding,由于同源策略的限制,XmlHttpRequest只允许请求当前源(协议,域名,端口)的资源.如果要进行跨域请求,我们可以 ...