Created
March 17, 2020 03:51
-
-
Save Eduardo-Nunes/9fd3676659a5910d9bd9917b5cc05aae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean exit; | |
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { | |
@Override | |
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { | |
Log.d("onOffsetChanged", "appbar verticalOffset: " + verticalOffset); | |
if (verticalOffset == 0 && !exit) { | |
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams(); | |
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED); // list other flags here by | | |
collapsingToolbar.setLayoutParams(params); | |
exit = true; | |
} else if (verticalOffset <= -300 && rvUserProfile.computeVerticalScrollOffset() <= 25 && exit) { | |
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams(); | |
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS); // list other flags here by | | |
collapsingToolbar.setLayoutParams(params); | |
exit = false; | |
} | |
} | |
}); | |
rvUserProfile.setOnScrollListener(new RecyclerView.OnScrollListener() { | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
if (dy < 0 && recyclerView.computeVerticalScrollOffset() <= 25 && exit) { | |
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams(); | |
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS); // list other flags here by | | |
collapsingToolbar.setLayoutParams(params); | |
exit = false; | |
} else if (dy > 0 && recyclerView.computeVerticalScrollOffset() >= 25 && !exit) { | |
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams(); | |
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED); // list other flags here by | | |
collapsingToolbar.setLayoutParams(params); | |
exit = true; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment