关于ScrollView和listview的冲突关于的滑动和宽度
listview和ScrollView嵌套有两个冲突,关于listview显示不全的问题和listview和scrollview的滑动冲突
自定义listview
package com.exmple.listscrow; import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
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
// =
heightMeasureSpec = MeasureSpec.makeMeasureSpec(500/*
* Integer.MAX_VALUE
* >> 2
*/,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
解决滑动的冲突
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
getParent().requestDisallowInterceptTouchEvent(true);
return super.dispatchTouchEvent(ev);
} }
在主方法里贴以下代码,以下这个代码可以实现以下效果,当listview滑到底部的时候,
ScrollView会和listview实现连动
package com.exmple.listscrow; import java.util.ArrayList;
import java.util.List; import com.exaple.vo.Super; import android.R.fraction;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.Toast; public class MainActivity extends Activity implements OnScrollListener {
String[] name = new String[] { "陈克", "陈多多", "张小杰", "张杰", "宋静萌", "郑芳蓓",
"杨洋", "谢娜", "刘忠杰", "天下", "走路去纽约", "一切都值得", "最美的太阳", "我们都一样",
"娜样纯洁的爱恋", "一切都值得", "最美的太阳", "我们都一样", "娜样纯洁的爱恋" };
String[] price = new String[] { "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" };
private List<Super> list;
boolean island;
private MyListView listview;
private ScrollView sc; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (MyListView) findViewById(R.id.listview);
sc = (ScrollView) findViewById(R.id.sc);
getData();
Apap ap = new Apap(list, MainActivity.this);
listview.setAdapter(ap);
listview.setOnScrollListener(this);
//不用自定义listview时用
/*listview.setOnTouchListener(new OnTouchListener() { @Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == 2) {
sc.requestDisallowInterceptTouchEvent(true);
} else {
sc.requestDisallowInterceptTouchEvent(false); }
return false;
}
});
*/
// listview.getParent().requestDisallowInterceptTouchEvent(false);
} public List<Super> getData() {
list = new ArrayList<Super>(); for (int i = 0; i < name.length; i++) {
Super super1 = new Super();
super1.setName(name[i]); list.add(super1); }
return list;
} //
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (island && scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Toast.makeText(MainActivity.this, "kaisjia", 0).show();
sc.requestDisallowInterceptTouchEvent(false); } } @Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) { island = (firstVisibleItem + visibleItemCount) == totalItemCount; }
}
关于ScrollView和listview的冲突关于的滑动和宽度的更多相关文章
- [Android] Android最简单ScrollView和ListView滚动冲突解决方案
[Question]问题描述: 单独的ListView列表能自动垂直滚动,但当将ListView嵌套在ScrollView后,会和ScrollView的滚动滑块冲突,造成ListView滑块显示不完整 ...
- ScrollView与ListView的冲突
众所周知ListView与ScrollView都具有滚动能力,对于这样的View控件,当ScrollView与ListView相互嵌套会成为一种问题: 问题一:ScrollView与ListView嵌 ...
- 解决ScrollView与ListView事件冲突
1,在最近做项目的时候使用ScrollView嵌套ListView的时候发现ListView的滑动效果失效,简单的网上搜索了一下,也就有了下面的解决方法,在ListView中设置事件的监听listvi ...
- ScrollView和ListView的冲突问题
在ScrollView添加一个ListView会导致listview控件显示不全,这是因为两个控件的滚动事件冲突导致.所以需要通过listview中的item数量去计算listview的显示高度,从而 ...
- Android ScrollView与ListView的冲突解决办法汇总
1. public void setListViewHeight(){ ListAdapter listadapter = lv.getAdapter(); if (listadapter == n ...
- ScrollView和listview的冲突问题,关于宽度,和滑动
只需要重新listview即可 package com.exmple.listscrow; import java.util.logging.LogManager; import android.co ...
- Android布局中ScrollView与ListView的冲突的最简单方法
看到网上流行的一种使用方法是: public class Utility { public static void setListViewHeightBasedOnChildren(ListView ...
- ScrollView 嵌套ListView 幻灯冲突,和显示不全
import android.content.Context; import android.util.AttributeSet; import android.widget.ListView; /* ...
- android 有弹性的ScrollView 简单实现,与处理ScrollView和ListView,GridView之间的冲突
处理ScrollView和ListView,GridView之间的冲突, 最好的办法就是继承这两个类,重写他们的onMeasure方法即可: ListView: import android.widg ...
随机推荐
- URL编码:不同的操作系统、不同的浏览器、不同的网页字符集,将导致完全不同的编码结果。
URL编码:不同的操作系统.不同的浏览器.不同的网页字符集,将导致完全不同的编码结果. 因此如果Url中有中文或特殊字符,一定要自己调用函数编码解码,不要让浏览器帮你编码,否则出现了问题会浪费你很多时 ...
- 使用Privoxy做智能代理切换
使用Privoxy做智能代理切换 You take the blue pill, the story ends, you wake up in your bed, and believe whatev ...
- [LintCode] Flatten Binary Tree to Linked List 将二叉树展开成链表
Flatten a binary tree to a fake "linked list" in pre-order traversal. Here we use the righ ...
- Convert between cv::Mat and QImage 两种图片类转换
在使用Qt和OpenCV混合编程时,我们有时需要在两种图片类cv::Mat和QImage之间进行转换,下面的代码参考了网上这个帖子: //##### cv::Mat ---> QImage ## ...
- orcale 动态执行语句
create or replace function fn_test2(tablename in varchar2) return number is rtn number; begin --通用的获 ...
- Flashback闪回技术小实验
1闪回查询 2闪回删除 3闪回版本查询 4闪回事务查询 5闪回某张表 6闪回数据库
- 文件代码对比软件 Beyond Compare
Beyond Compare https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=Beyond%20Co ...
- C# - 时间格式
如果是字符串,需要先转化为DateTime格式 DateTime ExDate = DateTime.Parse(dt.Rows[]["HKMonth"].ToNotNullStr ...
- IOS第18天(6,CAKeyframeAnimation关键帧动画)
******* #import "HMViewController.h" @interface HMViewController () @property (weak, nonat ...
- Session 知识点再整理(二) 自定义 Session 存储机制
对于访问量大的网站,用默认的 Session 存储方式(以文件存储)不适合,因为文件的 I/O 开销会非常大,另外 Session 机制本身使 Session 不能跨机访问,在 Web 集群中无法达到 ...