-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Header reappears on top when returning to fragment that has been scrolled down. #59
Comments
Hey! If state is not restored automatically, you can manually save |
Yea the fragment hosting the scrollable layout hits the onDestroyView when returning to it from the fragment above it. |
Well, if fragment went through getArguments().putInt("key", scrollableLayout.getScrollY()); and in scrollableLayout.setScrollY(getArguments().getInt("key", 0)); |
I tried that and doesn't seem to be working. My onViewCreated looks like this
the first log is showing 545 but when I print the scrollableLayout.getScrollY() it prints 0. |
Hm. Are you by any chance using |
Yea im using autoMaxScroll and logging getMaxScrollY() before applying setScrollY() is showing 0 too. |
Yeah, so I thought. I think there is a bug with state restoration in ScrollableLayout. Meanwhile, you could something like that: @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final ScrollableLayout scrollableLayout = view.findViewById(R.id.scrollable_layout);
// your initialization
final int savedScrollY = getArguments().getInt("key");
if (savedScrollY > 0) {
scrollableLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// here we might validate that scrollableLayout was called first
if (scrollableLayout.getMaxScrollY() > 0) {
scrollableLayout.setScrollY(savedScrollY);
scrollableLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
}
} |
Cool, it Worked!! Thanks for the quick response. |
Currently, in my project, I have a fragment that has a scrollable layout that hosts a header image and a recycler view. When scrolling down and hitting a button at the bottom of the recycler view a new fragment is added to the stack. When returning to the original fragment that has the scrollable layout the header appears at the top even though the recycler view is still scrolled to the bottom. What would be the best way to retain the headers state so when returning to the fragment the header is not shown if the recycler view is currently scrolled all the way down?
The text was updated successfully, but these errors were encountered: