I implemented ItemDecoration into my RecyclerView along with an Animation that plays whenever the RV is loaded. However, I noticed that the decoration appears already at the bounds before the animation completes, and I want to have the decoration move in with the animation at the same time. How would I do this?
So far, I have been entering the animation like so:
@Override
public void onBindViewHolder(final RecyclerVH recyclerVH, final int position) {
currentNote = data.get(position);
final String currentTitle = currentNote.getTitle();
final String currentContent = currentNote.getContent();
final int currentPosition = currentNote.getPosition();
String currentAlarmDate = currentNote.getAlarm();
Log.d("RecyclerView", "onBindVH called: " + currentTitle);
Log.d("RecyclerView", "Position at: " + currentPosition + " and Adapter Position at: " + recyclerVH.getAdapterPosition());
// final Info currentObject = data.get(position);
// Current Info object retrieved for current RecyclerView item - USED FOR DELETE
recyclerVH.listTitle.setText(currentTitle);
recyclerVH.listContent.setText(currentContent);
Log.d("RecyclerAdapter", "currentAlarmDate is: '" + currentAlarmDate + "'");
if (currentAlarmDate != null && !currentAlarmDate.equals(" ")) {
Log.d("RecyclerAdapter", "Current Alarm set for: " + currentAlarmDate);
recyclerVH.alarm.setText(currentAlarmDate);
} else
recyclerVH.alarm.setText(R.string.no_alarm);
/*recyclerVH.listTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Open new Activity containing note content
Toast.makeText(this, "Opening: " + currentObject.title, Toast.LENGTH_LONG).show();
}
});*/
runEnterAnimation(recyclerVH.itemView, position);
}
private void runEnterAnimation(View itemView, int position) {
// Starts Animation
Animation animation = AnimationUtils.loadAnimation(context,
position >= lastAnimatedPosition ? R.anim.up_from_bottom : R.anim.down_from_top);
// If true, up_from_button is loaded
itemView.startAnimation(animation);
lastAnimatedPosition = position;
Log.d("RecyclerAdapter", "lastAnimatedPosition is now: " + lastAnimatedPosition);
}
Seems like @Mimmo Grottoli's answer is the closest thing to a solution. Check out this post: How to disable RecyclerView item decoration drawing for the duration of item animations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With