2017-03-12 6 views
-1

Ich habe recycleview und ich muss Animation auf die Liste Elemente anwenden hier ist der Adapter und das Problem ist, dass die Zeilen animieren, aber es funktioniert nicht gut manchmal überlappt sich gegenseitig und irgendwann zu blinken jeden Vorschlag wird willkommen seinAndroid 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(); 
} 
    } 

und hier ist die Ressource Animation

<?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> 

Antwort

1

Deaktivieren Sie die Animation in onViewDetachedFromWindow Methode

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

} 
+0

danke lieber du hast meinen tag gerettet –