0

I have the following scenario:

  1. I have a custom view where I draw some graphs
  2. On top of the view I have a ViewPager + PagerTitleStrip

All works well, except for the fact, that ViewPager is blocking touches from falling through to the custom view. I need to tap on my graphs and show numbers.

I init the view pager like this:

    mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
    mDateViewPager = (ViewPager) findViewById(R.id.viewPager);
    mDateViewPager.setOffscreenPageLimit(0);
    mDateViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {}

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}

        public void onPageSelected(int position) {}
    });
    mDateViewPager.setAdapter(mStepsPagerAdapter);

Inside the custom view I overwrite onTouchEvent and performClick(); The custom view and the viewpager occupy the same screen area. I tried to return false on but it does not work either:

        mDateViewPager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return false;
        }
    });

Any idea how to make ViewPager "transparent" for touches?

  • Possible duplicate of [How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?](https://stackoverflow.com/questions/9650265/how-do-disable-paging-by-swiping-with-finger-in-viewpager-but-still-be-able-to-s) – Martin Zeitler Dec 01 '18 at 07:07
  • returning `true` might be the most easy way to get there. – Martin Zeitler Dec 01 '18 at 07:09
  • Returning `true` does 2 things: 1. Blocks swiping and 2. Still does not pass the touch event to the custom view. – Георги Ангелов Dec 01 '18 at 07:17
  • `ViewPager.onInterceptTouchEvent()` would be the other relevant method; because these clicks might be interpreted as swipe-start. setting up the `ViewPager` with a `TabLayout` would also ditch the swiping. does that chart use swipe events, too?? you possibly cannot have both at the same time - and that problem is not really reproducible with the amount of information provided. – Martin Zeitler Dec 01 '18 at 07:32
  • to enable `show layout boundaries` might help understanding the issue. `.setOffscreenPageLimit(0)` also tends to be problematic; see https://stackoverflow.com/a/32872290/549372. – Martin Zeitler Dec 01 '18 at 07:38

0 Answers0