amarjain07 / StickyScrollView

Sticky header and footer for android ScrollView.
MIT License
533 stars 86 forks source link

Footer keeps some space at the bottom in few devices #14

Closed malikmotani closed 2 years ago

malikmotani commented 5 years ago

download 1

In devices like Samsung M20 and few Honor devices, I found this issue. This is how I have fixed it but not sure it will work on every device.

 public int temp = 0;

 public void initStickyFooter(int measuredHeight, int initialStickyFooterLocation) {
        if (!heightAdded) {
            heightAdded = true;
            mStickyFooterHeight = (int) (measuredHeight + (MyApp.appContext.getResources().getDimension(R.dimen.space_sticky_footer)));

            if (temp == 0) {
                temp = getSoftButtonsBarHeight();
            }
            if (temp > 200) {
                mStickyFooterHeight -= temp / 2.1;
            }
        }
        mStickyFooterInitialLocation = initialStickyFooterLocation;
        mStickyFooterInitialTranslation = mDeviceHeight - initialStickyFooterLocation - mStickyFooterHeight;
        if (mStickyFooterInitialLocation  > mDeviceHeight - mStickyFooterHeight) {
            mStickyScrollPresentation.stickFooter(mStickyFooterInitialTranslation);
            mIsFooterSticky = true;
        }
}

private int getSoftButtonsBarHeight() {
        // getRealMetrics is only available with API 17 and +
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            DisplayMetrics metrics = new DisplayMetrics();
            MyApp.appContext.currentActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int usableHeight = metrics.heightPixels;
            MyApp.appContext.currentActivity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
            int realHeight = metrics.heightPixels;
            if (realHeight > usableHeight)
                return realHeight - usableHeight;
            else
                return 0;
        }
        return 0;
 }
amarjain07 commented 2 years ago

@malikmotani Did you update the system navigation from Gesture to 3-button while the screen with StickyScrollView was open in the background?

amarjain07 commented 2 years ago

Fixed in v1.0.3