Scrollview 嵌套listView 与recycleView 滑动冲突的解决

本来我们用recycview代替了listview之后就很少会遇到scrollview了但是产品需求总是在不断的更新。在时间与技术的探索之下,还是会有一部分兄弟会选择这样的布局,下面我就来说说使用之后遇到的一些坑的解决方案。


1 scrollview 签到listview 的解决方案

(1)

只需在MainActivity中 找到listview 和 scrollview

然后给listview设置监听事件  外部解决法

listView.setOnTouchListener(new OnTouchListener() {
            
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
              
                if(event.getAction() == MotionEvent.ACTION_UP){  
                    scrollView.requestDisallowInterceptTouchEvent(false);  
                }else{  
                    scrollView.requestDisallowInterceptTouchEvent(true);  
                }  
                return false;
            }
        });

或者


listView.setOnTouchListener(new OnTouchListener() {
            
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                listView.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });

第二种方法

只需重写listview即可 ,内部解决发

package com.bawei.day06;


import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;


public class ListViewForScrollView extends ListView {
    int mLastMotionY;
    boolean bottomFlag;
    public ListViewForScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        
        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 (chi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值