Aligned ViewPager Dynamic Center

I’m having trouble aligning the fragments in the center of the view pages, so that the user can see several fragments on the screen. This problem has already been solved earlier, but not when the fragments have different sizes.

Can a ViewPager have multiple views per page? is one of the links I used. The pagercontainer solution works on it, but very slowly. My solution was to install the ViewPager add-on using the setPadding(int, int, int, int) method and false for setClipToPadding . In this case, the fragments look as if they are centered, but assumes that all fragments are the same size (since setPadding is a global setting for the View ). Thus, the presence of different fragment sizes simply completely mixes the alignment.

I was hoping that if someone knows how to make the current fragment in the form of a pager can be aligned in the center without using a spacer. Thus, one could have different fragment sizes. Alternatively, can anyone suggest how to achieve center alignment with padding with variable fragment sizes?

PS: I searched everywhere on the Internet and could not find a solution.

+6
source share
1 answer

Instead of aligning the fragment inside the viewPager, why don't you try putting all your elements in the layout and then align it in the center (inside the fragment).

Make viewPager as wrap_content. and make the parameters of the main fragment layout as wrap_content too.

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

0
source

Source: https://habr.com/ru/post/976169/


All Articles