Ahmad Nasser Ahmad Nasser - 1 year ago 105
Java Question

Android Recycleview animation

I have recycleview and i need to apply animation on the list items here is the adapter and the problem is that the rows animate but its not work fine some times overlap each others and sometime make blinking any suggestion will be welcome

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) {
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;

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

public void onBindViewHolder(MyViewHolder holder, int position) {
Utils.setNotificationStatusColor(context, holder.notificationStatus, notifications.get(position).getStatusCode());
if (Utils.isArabicLanguage()) {
if (position > lastPosition) {

Animation animation = AnimationUtils.loadAnimation(context,
lastPosition = position;

public int getItemCount() {
return notifications.size();

and here is the animation resource

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

Answer Source

Clear the animation in onViewDetachedFromWindow method

public void onViewDetachedFromWindow(ViewHolder holder) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download