0

in viewpager when we scroll more than half of screen when we release it viewpager going to next page or previous page what I want is change that offset.
for example, when user scroll 200dp my viewpager going to next page.
can anyone help me about this?
thanks for any help.

max
  • 5,963
  • 12
  • 49
  • 80
  • You're gonna want to have a look at http://developer.android.com/training/animation/screen-slide.html where they talk about PageTransformer. That's where you define the behavior of the ViewPager – NSimon Apr 25 '16 at 13:22
  • Hi, nicolas thanks for your attention I see your link but there they talk about viewpager page transformers "animation when the page changes" and I could not find my answer there. – max Apr 25 '16 at 13:30

1 Answers1

0

The way a PageTransformer works is that it gives you access to a callback where you have 2 arguments : the page, and the position (between -1 : totally left, and +1 : totally right). This callback is as follow :

@Override
public void transformPage(View page, float position) {
    //Page (0, 1, 2 etc..) is the page
    //position goes from -1.0f (totally left) to +1.0f (totally right).
    //So you get access to each step of the animation for each position
    //and for each page.
    //You can then do something like : 
    page.setScaleX(1.0f + 0.05f * position);
    page.setScaleY(1.0f + 0.05f * position);
    //Which will scale the views up or down depending on where they are on the screen
}
NSimon
  • 5,212
  • 2
  • 22
  • 36
  • 1
    i think you miss understand my question , i do not want to change animation when user scroll in viewpager, i want to change minimum value to srcoll to change page in viewpager – max Apr 25 '16 at 14:18
  • 1
    Oh sorry. In that case you might want to have a look at the simpler approach : http://stackoverflow.com/a/17322361/4706693 or the hardest one : http://stackoverflow.com/a/11734445/4706693 – NSimon Apr 25 '16 at 14:24