I'd like to use a FragmentStatePageAdapter
and display 3 items at the same time.
This could be done by overriding the getPageWidth()
-Method:
@Override
public float getPageWidth(int position) {
return 0.33f;
}
This works great. But my problem is that I'd now like to have the centered page in focus. Currently the left page is in focus...
I've visualized the problem:
Currently:
Desired:
Desired 2 (If you scroll until the end):
What would you suggest?
Recapping the comment thread:
The issue regarding "focus" was due to the application of a PageTransformer
. PageTransformer
appears to be oblivious to getPageWidth()
and will transform only the first visible page.
To center the "first" page, you will need an invisible page before that one. ViewPager
always starts from the left, so the default would be to put the first page on the left. Having an invisible first page would put the first visible page in the next slot over. Note that depending on what behavior is desired for the end of the roster of pages, you may need one or more invisible pages there too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With