Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.