Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making ItemDecoration move with Animation

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);
}
like image 817
PlanetAstro_William Avatar asked Apr 25 '16 14:04

PlanetAstro_William


1 Answers

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

like image 159
PlanetAstro_William Avatar answered Oct 27 '22 02:10

PlanetAstro_William