Android Dev Tutorial: what is `Infinity` in the ViewPager example?

What is the code below in the Official Android Developer Tutorial Using ViewPager for Screen Slides ?

public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
    //...

    public void transformPage(View view, float position) {
        //...

        if (position < -1) { // **[-Infinity,-1)
            //...
        } else if (position <= 1) { // [-1,1]
            //...
        } else { // (1,+Infinity]
            //...
        }
    }
}
+4
source share
3 answers

The meaning of these comments is more or less:

if (position < -1) { // here go all 'position' values lesser than -1
    //...
} else if (position <= 1) { // 'position' in range from -1 to 1, including both -1 and 1
    //...
} else { // and then all 'position' values greater than 1 go here
    //...
}

If you are looking for the value of "infinity" for a type Floatin Android, then there are values ​​for Float.NEGATIVE_INFINITYand Float.POSITIVE_INFINITY.

+2
source

In the example on the site, the comment below actually explains the behavior

if (position < -1) { // [-Infinity,-1)
    // This page is way off-screen to the left.
    view.setAlpha(0);
}

-1, position if, ( ). -Infinity < position < -1 , , wille :

else if (position <= 1) { // [-1,1]
        //true for when position is less than or equal to 1
        //but only run when code is greater than or equal to -1
        //as this is an else-if
    } else { // [1,+Infinity]
        //true for when position is greater than 1
    }

position , .

, , -1 , . , , .

+1

, view ( ) ( ), , - 0

You should understand that this is the code used to describe the transition viewwhen scrolling through fragments ViewPager, so when viewit is still displayed on the screen, you apply scaleFactor, and when it is turned off, just set it to invisible or alpha 0.

+1
source

All Articles