henrytao-me/smooth-app-bar-layout

initial state of SmoothAppBarLayout

fgutmann opened this issue · 2 comments

We have a RecyclerView and a SmoothAppBarLayout working in combination.
The linear layout manager of the recycler view has set setStackFromEnd(true) which causes it to be scrolled to the bottom initially.

Everything works as expected when scrolling and flinging but initially the header image is always fully expanded. As soon as you scroll just a little, it jumps back to the correct (collapsed) state.

Is there some way to refresh the state of the SmoothAppBarLayout in code to make it adjust to the current scroll position of the recycler view?

Here is the layout file:

<android.support.design.widget.CoordinatorLayout
	android:id="@+id/coordinator_layout"
	android:layout_width="match_parent"
	android:layout_height="0dp"
	android:layout_weight="1">

	<android.support.v7.widget.RecyclerView
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:id="@+id/recycler_view" />

	<me.henrytao.smoothappbarlayout.SmoothAppBarLayout
		android:id="@+id/appbar_layout"
		android:layout_height="@dimen/profile_header_height"
		android:layout_width="match_parent">

		<ImageView
			android:layout_width="match_parent"
			android:layout_height="match_parent"
			app:layout_scrollFlags="scroll"
			android:scaleType="centerCrop"
			android:src="@drawable/profileimage_placeholder_female"/>
	</me.henrytao.smoothappbarlayout.SmoothAppBarLayout>
</android.support.design.widget.CoordinatorLayout>

Btw, thank you for this great library! 👍

Hi @fgutmann

WhatsApp did the same thing as you mentioned. Someone has been asked for that feature as far as I remember. However, due to current approach of SmoothAppBarLayout, it is really tricky to do it (total vertical scroll-offset needs to have min-height as screen-height + init-scroll-value). I believe with original AppBarLayout, it is much much easier. I would say we can wait for Chris Banes in AppCompat team. He is currently working on the fix for AppBarLayout. Hopefully it will be released soon.

Thanks,
Henry

Hi Henry,

I don't fully understand how currently the SmoothAppBarLayout works. Unfortunately waiting isn't really an option for us. We need to either find a workaround now for this issue or find a totally different solution.

Can you maybe explain to me in a little bit more detail what is going on and causing the issue?
My observation is that every programmatically triggered scrolling is ignored by the app bar layout.
Does it react directly to the gestures of the user?

Also when I scroll just a little manually, it jumps to the correct state. Out of this I get hope that we can maybe simulate such a scroll event to make it adjust correctly? Maybe by triggering some scroll events directly on the Behaviour?

We are just looking for a workaround that does the job for now. Then when the new AppBarLayout is released we'll migrate to this if possible.

Do you have any idea for such a workaround?