使用动画使ItemDecoration移动

时间:2016-04-25 14:22:10

标签: android android-recyclerview

我将ItemDecoration实现到我的RecyclerView以及每当加载RV时播放的动画。但是,我注意到装饰在动画完成之前已经出现在界限处,我想让装饰同时移动到动画中。我该怎么做?

到目前为止,我一直在进入动画:

@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);
}

2 个答案:

答案 0 :(得分:1)

似乎@Mimmo Grottoli的答案是最接近解决方案的。看看这篇文章:How to disable RecyclerView item decoration drawing for the duration of item animations

答案 1 :(得分:-3)

您可以阅读documentation

或者如果需要动画装饰,你可以试试这个:

https://github.com/slidenerd/materialtest

谢谢,如果你没有得到它的解决方案,请问我,我会尽力给你一个更好的解决方案。 :)