andraskindler / parallaxviewpager

[Development stopped in 2014. Unfinished and not stable - not recommended to use.] An easy-to-use ViewPager subclass with parallax background effect for Android apps.
438 stars 86 forks source link

onSizeChanged selective execution #9

Open edualonso opened 9 years ago

edualonso commented 9 years ago

Hi. It seems that every time the soft keyboard pops up, the method onSizeChanged is called and the background resource drawn again, which means that the image will sqeeze vertically. It would be nice if the pager included a "allowBackgroundResize(boolean allow)" method, so we could disable it if, for example, the keyboard pops up.

edualonso commented 9 years ago

I have solved it adding a flag, and modifying the onSizeChanged method:

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    destination.top = 0;
    destination.bottom = overrideBackgroundResize ? h : oldh;
    if (overrideBackgroundResize) {
        super.onSizeChanged(w, h, oldw, oldh);
    } else {
        overrideBackgroundResize = true;
        super.onSizeChanged(oldw, oldh, oldw, oldh);
    }
    if (getAdapter() != null && bitmap != null) {
        calculateParallaxParameters();
    }
}

Every time we want to override the pager's drawing behavior, we simply change the "overrideBackgroundResize" flag.

andraskindler commented 9 years ago

Great job, thanks! Submit a PR and I'll merge it.