Solution 1 :
You can use YoYo library from github have all animation and very easy to use
https://github.com/daimajia/AndroidViewAnimations
You can use this any where
Simple use it inside onscrollchanged method of recyclerview
Problem :
I have a RecylcerView and a view which is above it and I want to hide it when I scroll down. I have found a way which kind of works, but it’s pretty janky and sometimes takes the speed out of the scrolling action. How do I make it more fluent?
Layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns_android="http://schemas.android.com/apk/res/android"
xmlns_app="http://schemas.android.com/apk/res-auto"
xmlns_tools="http://schemas.android.com/tools"
android_layout_width="match_parent"
android_layout_height="match_parent"
tools_context=".ui.Items.ItemsFragment">
<FrameLayout
android_id="@+id/frameLayout"
android_layout_width="match_parent"
android_layout_height="0dp"
android_layout_marginTop="8dp"
app_layout_constraintBottom_toBottomOf="parent"
app_layout_constraintEnd_toEndOf="parent"
app_layout_constraintStart_toStartOf="parent"
app_layout_constraintTop_toBottomOf="@+id/cardViewSearch">
<androidx.recyclerview.widget.RecyclerView
android_id="@+id/recylcerViewItems"
android_layout_width="match_parent"
android_layout_height="match_parent"
android_divider="@android:color/transparent"
android_dividerHeight="8dp"
android_scrollbars="vertical"
android_visibility="visible"
app_layout_constraintBottom_toBottomOf="parent"
app_layout_constraintEnd_toEndOf="parent"
app_layout_constraintStart_toStartOf="parent"
app_layout_constraintTop_toBottomOf="@+id/chipGroup" />
<com.google.android.material.chip.ChipGroup
android_id="@+id/chipGroup"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_clipToPadding="false"
android_padding="8dp"
android_visibility="visible"
app_layout_constraintEnd_toEndOf="parent"
app_layout_constraintStart_toStartOf="parent"
app_layout_constraintTop_toBottomOf="@+id/cardViewSearch">
<com.google.android.material.chip.Chip
android_id="@+id/toolsChip"
style="@style/Widget.MaterialComponents.Chip.Action"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_elevation="4dp"
android_fontFamily="@font/nunito_regular"
android_text="@string/item_tools"
android_textColor="@color/colorChipText"
app_chipBackgroundColor="@color/colorChipTools"
app_chipIcon="@drawable/ic_tool_black_24dp"
app_chipIconTint="@color/colorChipText" />
<com.google.android.material.chip.Chip
android_id="@+id/blocksChip"
style="@style/Widget.MaterialComponents.Chip.Action"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_elevation="4dp"
android_fontFamily="@font/nunito_regular"
android_text="@string/item_blocks"
android_textColor="@color/colorChipText"
app_chipBackgroundColor="@color/colorChipBlocks"
app_chipIcon="@drawable/ic_block_black_24dp"
app_chipIconTint="@color/colorChipText" />
</com.google.android.material.chip.ChipGroup>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I want to hide the ChipGroup. There are more Chips in the group, but I removed them here.
Hide Code right now:
final ChipGroup chipGroup = (ChipGroup) root.findViewById(R.id.chipGroup);
mRecyclerView.setPadding(0, chipGroup.getHeight(), 0,0);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if(newState == RecyclerView.SCROLL_STATE_IDLE){
if(!showFilteredResults) {
showFilteredResults = true;
}
} else {
if(showFilteredResults) {
showFilteredResults = false;
}
}
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
FrameLayout frameLayout = (FrameLayout) root.findViewById(R.id.frameLayout);
if (dy > 0 && HIDE_VIEWS_ON_SCOLL) {
// scrolling up
Log.i("scroll", "up");
TransitionManager.beginDelayedTransition(frameLayout, new ChangeBounds());
chipGroup.setVisibility(View.GONE);
mRecyclerView.setPadding(0, 0,0,0);
} else if (dy < 0 && HIDE_VIEWS_ON_SCOLL){
// scrolling down
Log.i("scroll", "down");
TransitionManager.beginDelayedTransition(frameLayout, new ChangeBounds());
chipGroup.setVisibility(View.VISIBLE);
mRecyclerView.setPadding(0, chipGroup.getHeight(),0,0);
}
super.onScrolled(recyclerView, dx, dy);
}
});