6

I'm having trouble aligning the fragments to the center of the view pages, in a way that the user can see multiple fragments on the screen. This problem has already been solved before, but not when the fragments have different size.

Can ViewPager have multiple views in per page? is one link that I used. The pagercontainer solution on it works but is very slow. My solution was to set ViewPager padding through setPadding(int, int, int, int) method and false for setClipToPadding. Doing so makes the fragments look as if they're aligned in the center, but assumes that all fragments are the same size (since setPadding is a global setting for a View). So having different fragment sizes just completely messes the alignment.

I was hoping if someone knew how to make it so that the current fragment in view pager can be aligned to center without the use of padding. That way one could have different fragment sizes. Alternatively, could someone suggest how to achieve center alignment with padding with variable fragment sizes?

PS: I've searched everywhere online and couldn't find a solution.

Community
  • 1
  • 1
nikd
  • 71
  • 2

1 Answers1

0

Rather than aligning the fragment inside the viewPager, why dont you try putting all your elements in a layout and then align it to center(inside the fragment).

Make viewPager as wrap_content. and make fragment main layout params as wrap_content too.

If this does not help you. You can share your layout.Also, add one more tag to your question - "android_layout"

Yashika
  • 173
  • 1
  • 6