listView界面改变后滑动时的复用问题
2016-03-09 23:14
330 查看
listView中Item有事件处理并且改变了子布局中某控件的呈现时,由于getView()返回View的复用性,导致滑动的时候出现复用的样式,具体问题如下:内部监听问题可参照:http://blog.csdn.net/tom_xiaoxie/article/details/50827185解决办法:重写listView的onMeasure()方法:
public class ScrollListView extends ListView{ public ScrollListView(Context context) { super(context); } public ScrollListView(Context context, AttributeSet attrs) { super(context, attrs); } public ScrollListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // super.onMeasure(widthMeasureSpec, heightMeasureSpec); int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }将之前用到的ListView换成重写后的ListView,并在外层布局嵌套一层ScrollView。这样就可以解决问题。修改后的布局如下:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <com.example.tom.study.testListView.ScrollListView android:id="@+id/test_listIner" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> </RelativeLayout>
这种解决方式跟ScrollView中嵌套ListView滑动冲突解决的方式一样,可查看:http://blog.csdn.net/tom_xiaoxie/article/details/50500538
相关文章推荐
- 快捷键啊
- 骨骼动画详解-Spine
- 告诉我,这其实是一个悲剧 -_-#
- Web网络相关_如何实现实时更新?
- 软件工程个人作业01
- 关键字
- 小代码
- linux用户ssh公钥登录主机的方法
- IOS学习 UITableView 委托方法
- NPOI 2.1.3.1版本读取excel 2003 2007,2013版本的xlsx文件
- floyd算法
- Climbing Stairs
- nyoj--20 吝啬的国度(dfs)
- JAVA移位运算符
- 小代码3 魔方矩阵
- 多个参数的方法
- Block再识
- 集体智慧编程——优化搜索算法:爬山法,模拟退火算法,遗传算法-Python实现
- Linux 字符设备驱动结构(一)—— cdev 结构体、设备号相关知识解析
- C语言详解 枚举