2017-03-12 8 views
-1

私はリサイクルビューを持っていますが、ここではリスト項目にアニメーションを適用する必要があります。アダプターは問題ありませんが、行はアニメーション化されますが、うまく動作しない場合もあります。Android Recycleview animation

public class ActionsAdapter extends   RecyclerView.Adapter<ActionsAdapter.MyViewHolder> { 

private Context context; 
private List<Notification> notifications; 
private int lastPosition=-1; 

public void setNotifications(List<Notification> notifications) { 
    if (notifications == null) { 
     this.notifications = new ArrayList<>(); 
    } else { 
     this.notifications = notifications; 
    } 
} 

public class MyViewHolder extends RecyclerView.ViewHolder { 
    TextView notificaytionText; 
    TextView notificationStatus; 

    ImageView notificationIndecator; 
    View view; 

    public MyViewHolder(View view) { 
     super(view); 
     this.view = view; 
     notificaytionText = (TextView) view.findViewById(R.id.notification_text); 
     notificationStatus = (TextView) view.findViewById(R.id.notification_status); 
     notificationIndecator = (ImageView) view.findViewById(R.id.notification_indecator); 
    } 
} 

public List<Notification> getNotifications() { 
    return notifications; 
} 

public ActionsAdapter(Context context) { 
    this.context = context; 
} 

@Override 
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View itemView = LayoutInflater.from(parent.getContext()) 
      .inflate(R.layout.row_actions, parent, false); 
    return new MyViewHolder(itemView); 
} 

@Override 
public void onBindViewHolder(MyViewHolder holder, int position) { 
    holder.notificaytionText.setText(notifications.get(position).getSubmittedBy()); 
    Utils.setNotificationStatusColor(context, holder.notificationStatus, notifications.get(position).getStatusCode()); 
    if (Utils.isArabicLanguage()) { 
     holder.notificaytionText.setGravity(Gravity.RIGHT); 
     holder.notificationIndecator.setRotation(180); 
    } 
    FontManager.setViewRebotoFont(context,holder.notificaytionText,FONTS.REGULAR,0); 
    if (position > lastPosition) { 

     Animation animation = AnimationUtils.loadAnimation(context, 
       R.anim.recycle_from_right 
     ); 
     holder.itemView.startAnimation(animation); 
     lastPosition = position; 
    } 
} 

@Override 
public int getItemCount() { 
    return notifications.size(); 
} 
    } 

、ここでアニメーションリソース

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:shareInterpolator="false"> 
<translate 
    android:fromXDelta="100%" android:toXDelta="0%" 
    android:fromYDelta="0%" android:toYDelta="0%" 
    android:duration="900" /> 
</set> 

答えて

1

クリアonViewDetachedFromWindow方法でアニメーション

@Override 
public void onViewDetachedFromWindow(ViewHolder holder) { 
    holder.itemView.clearAnimation(); 

} 
です
+0

あなたは私の一日を保存してくれてありがとう –