0

I have the requirement for what is effectively two activities side by side, allowing the user to scroll from one to the other, and back. I've decided that ViewPager is probably the best way to handle this, but am open to suggestions.

When the activity loads, the left hand view is displayed. I want to indicate to the user that the other view exists, by just scrolling it a small amount to the left and back again (similar to the way it's now common to show that a sliding drawer menu exists).

I've tried a number of things but have yet failed to find a method where both the views scroll smoothly together. Another way of interpretting the requirement is saying I want to programmatically fake a user flicking the page briefly.

androidneil
  • 880
  • 1
  • 10
  • 21

1 Answers1

2

Try calling the method fakeDragBy(float)! According to the documentation you need to first call beginFakeDrag() to initiate it and then call endFakeDrag(). This will mantain the ViewPagers default snapping behavior, so once you've revealed the other screen is there you don't have to animate the transition back, simply call endFakeDrag and the ViewPager will correctly snap back to the last screen (As long as you haven't dragged it past the half-way mark).

cincy_anddeveloper
  • 1,140
  • 1
  • 9
  • 19
  • Thank you for drawing my attention to these methods, which I hadn't seen before. I have found a couple of examples which are claimed to work, so will give it a try. – androidneil Dec 05 '17 at 18:27
  • 1
    The example code to make this work is explained here: https://stackoverflow.com/questions/25475882/android-viewpager-bounce-to-half-a-page/25476109#25476109 – androidneil Dec 06 '17 at 08:50
  • @androidneil If my answer helped solve you problem, would you mind accepting it? – cincy_anddeveloper Dec 06 '17 at 15:36