Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Ratik Sharma
Ratik Sharma
32,885 Points

Implementing a custom ViewPager to allow viewing the layout next to (right, left or both) the current Fragment

The Problem: The project I'm working on has multiple custom themes in it and I want to present them to the user with a ViewPager. Here's what I want to accomplish:

theme_selection mockup

What I've accomplished: I have a working ViewPager with displays the layouts I have set up but the only way I tell the user that there are other themes to choose from on the right is by using a PagerTitleStrip to display a name for each Page in the ViewPager and this is not what I want.

Possible fix I thought of: Placing a rectangular image in the layout file (refer mockup) to inform the user about the next them. The problem with this is that swiping will reveal the gimmick and destroy the entire UI.

Any help is appreciated!

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

I did exactly this a while ago at an old job. Sadly it was proprietary code so I don't have any to share. But if I remember correctly, I used a horizontal ScrollView that had a width less than the width of its parent, a LinearLayout that matched the width of the screen. I set margins to allow for spacing between items, and I added some onFling() code like in this StackOverflow answer to stop the ScrollView from advancing more than one item at a time.

You may be able to configure the ViewPager like this; I just haven't tried it myself. In fact, here's another StackOverflow answer that looks promising.

Ratik Sharma
Ratik Sharma
32,885 Points

All this sounds a tad bit complex but I'll give it a go and get back to the discussion! Thanks.

PS. Do you think you could do a workshop regarding such an implementation?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

I'll add it to my list of workshop ideas. It is a bit complex but it would be a good learning experience.