Scrollview嵌套listview
//建立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的更多相关文章
- 关于ScrollView嵌套ListView问题
Android开发之ScrollView中嵌套ListView的解决方案 原文:http://blog.csdn.net/minimicall/article/details/40983331 ...
- 四种方案解决ScrollView嵌套ListView问题(转)
以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...
- android 解决ScrollView嵌套ListView的问题,不能全屏,全屏不能显示下面控件
在开发中遇到ScrollView嵌套ListView的问题,最开始发出不能全屏,效果是这样的: 但我想要的效果是这样的: 下面看一下布局文件: <?xml version="1.0&q ...
- ScrollView嵌套ListView的滑动冲突问题,是看大神的方法的,作为学习以后用的到
在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollView嵌套ListView结 ...
- ScrollView嵌套ListView嵌套GridView的上下拉以及加载更多
ScrollView 效果 ScrollView 说明 一个ScrollView 嵌套ListView 嵌套GridView的上拉加载更多,下拉刷新的demo. 主要是重写了GridView和Lsit ...
- 四种方案解决ScrollView嵌套ListView问题
在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollView嵌套ListView结 ...
- 转:四种方案解决ScrollView嵌套ListView问题
转载自:http://blog.sina.com.cn/s/blog_46798aa80101lxbk.html 原始的连接已经不知道是哪里了,项目中遇到了同样的问题,花了一下午都没有想到是嵌套引起的 ...
- 四种方案解决ScrollView嵌套ListView问题[转]
http://bbs.anzhuo.cn/thread-982250-1-1.html 以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多 ...
- ScrollView嵌套ListView显示不完全、嵌套TextView不能滚动解决办法
目录: 一.情景说明 二.最初做法 三.解决办法 一.情景说明 1.情景 最近项目刚好有一个需求,需要在一个界面中用ScrollView嵌套一个滚动的TextView和一个listView ...
- ScrollView嵌套ListView只显示一行
错误描述 ScrollView嵌套ListView中导致ListView高度计算不正确,只显示一行. 解决方法 重写ListView的onMeasure方法,代码如下. @Override publi ...
随机推荐
- walk around by The provided App differs from another App with the same version and product ID 分类: Sharepoint 2015-07-05 08:14 4人阅读 评论(0) 收藏
'm currently developing a SharePoint 2013 application. After a few deployments via Visual Studio, I ...
- android退出MainActivity后onDestroy不回调
问题:有时点击back键,退出MainActivity后,app已不可见,但是onDestroy却没有被调用. 原因: 1. onBackPressed被覆盖 @Override public voi ...
- Sqrtx
我只能想出二分的方法,而且还不一定能写出最简洁的代码.无论刷多少遍,牛顿迭代法我都想不到,莫名有种悲哀的感觉:智力是硬伤啊.就算如此,却还要一遍遍不厌其烦地刷,这才是最悲剧的.多说无益,上代码. 二分 ...
- linux学习之九 学习过程总结
~写在前面 首先非常感谢孟老师的悉心讲解,使用这种新颖的教学方式(MOOC课堂+博客),也感到非常有幸随着老师的思路对linux的内核进行了初步的系统学习.结合代码和gdb调试工具跟踪分析对linux ...
- linux环境下安装jdk
1.查看系统自带的jdk #RPM -qa|grep jdk 若存在则删除 jdk-1.7.0_67-fcs.x86_64 #rpm -e --nodeps jdk-1.7.0_67-fcs.x86_ ...
- C++多线程2
#include "stdafx.h" #include <windows.h> int g_count; ; DWORD __stdcall Func(LPVOID ...
- vim自动补全功能
1.首先下载一个插件:ctags 输入:sudo apt-get install ctags 2.Ctrl+n进行单词的自动补全
- Nginx 1.10.2 发布,高性能 Web 服务器
Nginx 1.10.2 发布了.Nginx(发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器 更新内容: Changes with n ...
- 查看数据库中没有进行comment的字段
为落实数据库规范,既每个表字段都需要有comment注释,所以需要过滤生产表中没有comment的字段,搜索出还不错的过滤语句 show full columns from table where C ...
- java类中成员的划分