user2410644
user2410644

Reputation: 3891

ViewPager showing border of fragment

I'd love to know if anybody knows how to achieve following:

I've got a ViewPager showing up a fragment. While this fragment is showing, You can see the small left border of the fragment to the right. This fragment can be pulled out and acts like a NavigationDrawer.

Here's an example, the Android L Calculator app:

https://d13yacurqjgara.cloudfront.net/users/409459/screenshots/1647461/calculatorrender.gif

enter image description here

As You can see, there is a small blueish border to the right which can be pulled out by swiping it in just like a NavigationDrawer.

Any suggestions how this is achieved?

Upvotes: 0

Views: 520

Answers (1)

Daniel Zolnai
Daniel Zolnai

Reputation: 16910

From the looks of it, this is not done with a ViewPager.

If I would have to do this layout, I would do it with 2 ViewGroups next to each other. The first one would take 90% width of the screen, would be in the back, and aligned to the left, lets call this layout A.

The second one would take 75% width of the screen, placed in the front, aligned to the right, and have right margin of -65%. I would also add a nice shadow to its left edge, and call it layout B.

Layout A would have a grey background and lots of buttons, as in the animation. If the user swipes left on this view, you set a flag that layout B is shown, and animate the right margin of layout B, to show it. You would do the same when layout B is tapped while being almost hidden.

Any tap on layout A now would close layout B (you can control this with the flag). When tapped on a button in layout B, you also animate the right margin back, and set the flag also back to false.

If you would use fragments for this, then you would have to worry too much with the communication between the two, and it would just go the same way as with views.

Upvotes: 1

Related Questions