安卓:ListView控件与刷卡里面ViewPager控件、里面、ListView、ViewPager

2023-09-05 10:27:36 作者:青春年少为何不狂

我有一个ViewPager,涵盖了整个活动的活动。这里面ViewPager是一个ListView,即仅覆盖片段的底部。 ListView控件识别刷卡事件(可以刷卡项左右),但是当你想刷一个列表项目的ViewPager切换页面,所以这是行不通的。 有一种简单的方法来解决这一问题,从而使ViewPager不接收的,用于列表中的触摸事件。

I have an activity with a ViewPager that covers the whole activity. Inside this ViewPager is a ListView, that only covers the bottom part of the fragment. The ListView recognizes swipe events (you can swipe Items left and right) but when you want to swipe a list item the ViewPager switches the page, so it doesn't work. Is there an easy way to deal with this problem, so that the ViewPager doesn't receive the touch events that are intended for the list.

感谢

推荐答案

我的第一个想法是 requestDisallowInterceptTouchEvent()可以帮助你。

My first idea is requestDisallowInterceptTouchEvent() may help you.

public boolean onTouch(View v, MotionEvent e) {
    if(e.getAction() == MotionEvent.ACTION_DOWN){
       listItem.getParent().requestDisallowInterceptTouchEvent(true);
    }
}