Domanda

Background

FadingActionBar is a library that allows fading of the action bar based on scrolling of the content below it, while also having a header above the content .

The problem

What I wish to have is something like this for the header part:

  • vertical LinearLayout
    • imageView that takes the entire parent
    • bottom layout with some views.

the problem is that I wish the bottom layout to scroll with the content below the header, and that the imageView will scroll as usual, using the parrallex effect of the library.

the bottom layout is still inside the header part, so when scrolling enough, it should be hidden too.

What I've tried

I've tried negating the scrolling effect of the bottom layout by calling offsetTopAndBottom on it, within the addParallaxEffect method (inside the "FadingActionBarHelperBase.java" file) :

private void addParallaxEffect(final int scrollPosition) {
    final float damping = mUseParallax ? 0.5f : 1.0f;
    final int dampedScroll = (int) (scrollPosition * damping);
    int offset = mLastDampedScroll - dampedScroll;
    if (mStickeyView != null) {
        int stickeyOffset = mUseParallax ? (mLastScrollPosition - scrollPosition) / 2 : mLastScrollPosition - scrollPosition;
        mStickeyView.offsetTopAndBottom(stickeyOffset);
    }
    ...

this almost works well. it doesn't work when I scroll enough to hide the header and then go back , since it will accumulate scrolling over time.

The question

How can I correctly add this feature to the library?

Is there maybe a workaround?

È stato utile?

Soluzione

ok, i've fixed it by using:

if (mStickeyView != null) {
    final int stickeyOffset = -offset + mLastScrollPosition - scrollPosition;
    mStickeyView.offsetTopAndBottom(stickeyOffset);
}

however, if anyone else finds another, better way, please let me know.


EDIT:

The correct way to do it is by using headerOverlayLayout() for the bottom layout, as seen on the "HeaderOverlayActivity" sample.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top