Mohammad Zarei
Mohammad Zarei

Reputation: 1802

Vertical ViewPager with fragments

I want to show 3 fragments below each other. So far I've used many solutions such as YViewPager and answers such as Android: Vertical ViewPager. The main problem with them is non of them working the way I want. I need to show a first fragment and below that, some part of the second one, and when user scrolled to next one, showing second fragment and some part of third one. The YViewPager was great until I added these lines to show some part of second fragment:

viewPager.setClipToPadding(false);
viewPager.setCurrentItem(1);
viewPager.setPadding(0,0,0,500);

After that, it became like this:

With that white space that came out of nowhere. And as for other libraries and hacks which told me to swap motion event:

private MotionEvent swapXY(MotionEvent event) {
    float width = getWidth();
    float height = getHeight();

    float newX = (event.getY() / height) * width;
    float newY = (event.getX() / width) * height;

    event.setLocation(newX, newY);
    return event;
}

And also rewrite the PageTransformer. Here everything was good until I wanted to go from second fragment to the first one. It wanted to set the alpha to 0 to begin the transformation but this creates some sudden disappearance for the third fragment like this:

enter image description here

Well, here is my question:

Is there anyway to achieve this kind of view without these problems? Do you suggest some other approaches?

Thank you in advance.

Upvotes: 2

Views: 119

Answers (1)

Mondok Tamas
Mondok Tamas

Reputation: 1054

I think you can achieve the described behavior much easier using RecyclerView and SnapHelper. Here is a link where you can find some explanation with some sources https://rubensousa.github.io/2016/08/recyclerviewsnap

Upvotes: 1

Related Questions