问题描述
我有一个包含整个活动的 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);
}
}
这篇关于Android:在 ViewPager 内滑动的 ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!