Add animation to recyclerview

This commit is contained in:
Michael Schättgen 2018-12-17 23:28:56 +01:00
parent 4f0fea8a88
commit 1071192156
4 changed files with 58 additions and 4 deletions

View file

@ -1,5 +1,6 @@
package me.impy.aegis.ui.views;
import android.content.Context;
import android.graphics.PorterDuff;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@ -9,6 +10,8 @@ import androidx.recyclerview.widget.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import java.util.List;
@ -23,6 +26,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
private Listener _listener;
private SimpleItemTouchHelperCallback _touchCallback;
private RecyclerView _rvKeyProfiles;
private PeriodProgressBar _progressBar;
private boolean _showProgress;
@ -44,14 +48,18 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_progressBar.getProgressDrawable().setColorFilter(primaryColorId, PorterDuff.Mode.SRC_IN);
// set up the recycler view
RecyclerView rvKeyProfiles = view.findViewById(R.id.rvKeyProfiles);
_rvKeyProfiles = view.findViewById(R.id.rvKeyProfiles);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
rvKeyProfiles.setLayoutManager(mLayoutManager);
_rvKeyProfiles.setLayoutManager(mLayoutManager);
_touchCallback = new SimpleItemTouchHelperCallback(_adapter);
ItemTouchHelper touchHelper = new ItemTouchHelper(_touchCallback);
touchHelper.attachToRecyclerView(rvKeyProfiles);
rvKeyProfiles.setAdapter(_adapter);
touchHelper.attachToRecyclerView(_rvKeyProfiles);
_rvKeyProfiles.setAdapter(_adapter);
int resId = R.anim.layout_animation_fall_down;
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(getContext(), resId);
_rvKeyProfiles.setLayoutAnimation(animation);
_refresher = new UiRefresher(new UiRefresher.Listener() {
@Override
public void onRefresh() {
@ -71,6 +79,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_adapter.setGroupFilter(group);
_touchCallback.setIsLongPressDragEnabled(group == null);
checkPeriodUniformity();
runLayoutAnimation(_rvKeyProfiles);
}
public void refresh(boolean hard) {
@ -165,6 +175,16 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
checkPeriodUniformity();
}
private void runLayoutAnimation(final RecyclerView recyclerView) {
final Context context = recyclerView.getContext();
final LayoutAnimationController controller =
AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_fall_down);
recyclerView.setLayoutAnimation(controller);
recyclerView.getAdapter().notifyDataSetChanged();
recyclerView.scheduleLayoutAnimation();
}
public interface Listener {
void onEntryClick(DatabaseEntry entry);
void onEntryMove(DatabaseEntry entry1, DatabaseEntry entry2);

View file

@ -0,0 +1,26 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="400">
<translate
android:fromYDelta="-20%"
android:toYDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
/>
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:interpolator="@android:anim/decelerate_interpolator"
/>
<scale
android:fromXScale="105%"
android:fromYScale="105%"
android:toXScale="100%"
android:toYScale="100%"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="@android:anim/decelerate_interpolator"
/>
</set>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/item_animation_fall_down"
android:delay="15%"
android:animationOrder="normal"
/>

View file

@ -19,5 +19,6 @@
android:layout_height="0dp"
android:scrollbars="vertical"
android:id="@+id/rvKeyProfiles"
android:layoutAnimation="@anim/layout_animation_fall_down"
android:layout_weight="1"/>
</LinearLayout>