listview嵌套listview,底部的listview不能滑动问题

来源:互联网 发布:淘宝小号安全交易网 编辑:程序博客网 时间:2024/05/18 00:17

自定义一个listview

public class MyListView extends ListView {

public MyListView(Context context) {
super(context);
}

public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {// 当手指触摸listview时,让父控件交出ontouch权限,不能滚动
case MotionEvent.ACTION_DOWN:
setParentScrollAble(false);
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:// 当手指松开时,让父控件重新获取onTouch权限
setParentScrollAble(true);
break; }
return super.onInterceptTouchEvent(ev);} // 设置父控件是否可以获取到触摸处理权限
private void setParentScrollAble(boolean flag) {
getParent().requestDisallowInterceptTouchEvent(!flag);
}
}

然后在xml中使用

<so.king.MyListView
        android:id="@+id/li_lv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="@null"
        android:scrollingCache="false" />


引用 http://www.th7.cn/Program/Android/201408/262686.shtml

0 0
原创粉丝点击