Code example for ViewPager

Methods: getChildCount, onPageScrolled

0
            setBackgroundDrawable(wallpaper);
    } 
     
    @Override 
    protected void onPageScrolled(int position, float offset, int offsetPixels) {
        super.onPageScrolled(position, offset, offsetPixels);
        setIndicator(position, offset);
    } 
 
    private void setIndicator(int position, float offset) {
        int pages = Math.max(getChildCount(), pageCount);
        if(pages <= 1) {
            navListener.setMaskLevels(0, 0);
            return; 
        } 
        int levelLeft = (int)(10000 * (position + offset) / pages);
        int levelRight = (int)(10000 * (pages - 1 - position - offset) / pages);
        if(navListener != null) {
            navListener.setMaskLevels(levelLeft, levelRight);
        } 
    }