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 ...
随机推荐
- C++小项目:directx11图形程序(一):主框架
最近在学习DIRECTX11,在学习过程中编写了一个程序,到现在发现这个程序也有几行代码了,结构还算整齐,就想把这个程序分享出来,其中涉及到了C++程序的架构,windows窗口程序编写,和Direc ...
- Hibernate2
计应134(实验班) 杨伟 Hibernate 中提供了两级Cache(高速缓冲存储器),第一级别的缓存是Session级别的缓存,它是属于事务范围的缓存.这一级别的缓存由hibernate管理的,一 ...
- Python 数据类型笔记
Python有以下几种数据类型:1.字符串(str),2.布尔类型(bool),3.数字(int,float),4.列表(list),5.元组(tuple),6.字典(dict).1. 字符串. 对于 ...
- MVC WebAPI中响应客户端请求返回图片
// GET api/values public HttpResponseMessage Get() { Image img = GetImage(); MemoryStream ms ...
- swift 命名,字符串
命名: let numberOfDogs = 6 +2; 字符串连接: let finishedMessage = username + "xx" + password; 字符串 ...
- Java中文件的随机读写
[例 10-12]模仿系统日志,将数据写入到文件尾部. //********** ep10_12.java ********** import java.io.*; class ep10_12{ pu ...
- Linux内核分析——理解进程调度时机跟踪分析进程调度与进程切换的过程
20135125陈智威 +原创作品转载请注明出处 +<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 实验 ...
- Unity3D中可中途释放的单例
Unity3D中可中途释放的单例 使用静态类,静态变量的坏处是从程序加载后就一直占用内存,想要释放比较麻烦,可是之前使用的单例,没有提供释放的方法,那是不是也同静态的一样直到程序结束菜释放?那单例的好 ...
- android.app.Activity阅读摘要,有时候会不会需要保持一些现场数据呢? 想让系统帮你退出到后台或者挂掉前做些前置保持工作吗,重点参考吧:
* * @param savedInstanceState If the activity is being re-initialized after * previously being shut ...
- javac找不到或无法加载主类 com.sun.tools.javac.Main
在安装jdk后或者以前安装了jdk某时使用javac编译java文件时出现找不到或无法加载主类com.sun.tools.javac.Main,这个问题时,网上一般都说是环境变量配置不对,这样的说法其 ...