5

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:Current Pager

Desired: Desired Pager

Desired 2 (If you scroll until the end): Desired Page 2

What would you suggest?

Frame91
  • 3,670
  • 8
  • 45
  • 89
  • In terms of the focus, set the focus on the desired widget yourself. In terms of your bottom figure, that is not possible AFAIK, unless you have an `INVISIBLE` page 0. – CommonsWare Jan 01 '14 at 13:47
  • thanks for the reply. It's not just the focus. The current page is "highlighted" - a bit in the foreground and has another color – Frame91 Jan 01 '14 at 13:49
  • I am not aware that `ViewPager` highlights pages. Hence, AFAIK, the highlight effect is something that you are doing. – CommonsWare Jan 01 '14 at 13:52
  • maybe it's the fragmentstatepageadapter? the current page is a bit bigger and the other pages have some alpha value – Frame91 Jan 01 '14 at 13:56
  • sorry my fault, it's a zoom-out-page-transformer – Frame91 Jan 01 '14 at 13:58
  • Ah, I have not tried `PageTransformer` with `getPageWidth()`. I am not terribly surprised that there is a conflict there. I have no idea how to address that, sorry. – CommonsWare Jan 01 '14 at 14:04
  • no sorry, i wanted to mention that i'm indeed using a transformer... I can now handle my problem I guess ;) Thanks to you! – Frame91 Jan 01 '14 at 14:07
  • If you answer my question I can accept it. because now I got everything i need. I don't transform the page and I'm using a fake page 0 to get my second case ;) – Frame91 Jan 01 '14 at 14:11
  • I was the same problem... Can you share you code please ? – Crisic Jun 01 '15 at 16:10

1 Answers1

2

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491