0

Please, suggest a solution for the following scenario:

When a user clicks a button, the screen must be slid from right to left and the next screen must be shown. But the background for the both screens is the same (it's an image), and it is not slid, it stays at its place.

What can you suggest? Can I use activities here, or there must be fragments, or anything else?

mamba4ever
  • 2,662
  • 4
  • 28
  • 46
smb
  • 834
  • 1
  • 8
  • 17

1 Answers1

0

I found the solution. I created an activity and in the setContentView() function set a layout with a custom ViewPager. In the custom ViewPager the onTouchEvent() and onInterceptTouchEvent() functions are overriden and just return false.
The screens are implemented as Fragments. When a button is clicked, the viewPager's setCurrentItem() function is called and the corresponding screen is shown (the viewPager object is declared static and it can be called from a fragment).
Here is a good example of using ViewPager: http://www.javacodegeeks.com/2013/04/android-tutorial-using-the-viewpager.html
And this is an example of a custom view pager, where sliding is disabled: https://stackoverflow.com/a/13437997/2346046

Community
  • 1
  • 1
smb
  • 834
  • 1
  • 8
  • 17