如何让ListView放弃上下滑动手势的监听

2025-01-18 14:40:56
推荐回答(1个)
回答1:

自定义listview里面的控件,比如子view是viewpager用下面的一句代码就ok

import android.content.Context;

import android.support.v4.view.ViewPager;

import android.util.AttributeSet;

import android.view.MotionEvent;

public class MyViewPager extends ViewPager {

public MyViewPager(Context context) {

super(context);

}

public MyViewPager(Context context, AttributeSet attrs) {

super(context, attrs);

}

@Override

public boolean dispatchTouchEvent(MotionEvent event) {

getParent().requestDisallowInterceptTouchEvent(true); //让父类不拦截触摸事件

return super.dispatchTouchEvent(event);

}

}