DevBytes: ListView Animations
Why Stack Overflow recommends it
Stack Overflow users link it when ListView or GridView rows show wrong, duplicated or stale content because views get recycled during animations or async updates.
Recommended by 12 people across 11 different months, 2013 to 2015.
What it is
A short 2013 DevBytes episode from the Android Developers channel, presented by Chet Haase, on why animating ListView items goes wrong when views are recycled. It shows the transient state flag and the animation APIs added in Jellybean that fix it, with downloadable sample code.
What people said
Recommends Streets Of Boston · 2013-02 · Stack Overflow · on “Android: ListView bug”
The problem you experience could be that you animate a View (converView) that is being re-used for another item in your list-view when scrolling. Look at this YouTube video and you may get an idea on how to solve your problem. Chet Haase (Google engineer) "DevBytes" series "ListView Animations" : [this video] !
Recommends AdamK · 2013-04 · Stack Overflow · on “Listview items with Animation do not render properly”
Two things worth trying - For chaining animation operations use a listener: mPlaceHolder.animate() .alpha(0f) .scaleX(0.9f) .scaleY(0.9f) .rotationY(90) .setDuration(DURATION) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCacheableImage.setImageDrawable(drawable); mCacheableImage.animate() .alpha(1f) .scaleY(1f) .scaleX(1f) .rotationY(0) .setDuration(DURATION) .setListener(null); } }); Use setHasTransientState() [LINK] to ensure the views are not recycled in the ListView/GridView. See this DevByte video [this video] for more info.
Recommends AllDayAmazing · 2013-06 · Stack Overflow · on “Animate the removal of a ListView item”
As Chet Haase points out in DevBytes, [this video] , all of this will work but don't forget to add transientState flags. From his code: // Here's where the problem starts - this animation will animate a View object. // But that View may get recycled if it is animated out of the container, // and the animation will continue to fade a view that now contains unrelated // content. ObjectAnimator anim = ObjectAnimator.ofFloat(view, View.ALPHA, 0); anim.setDuration(1000); if (setTransientStateCB.isChecked()) { // Here's the correct way to do this: if you tell a view that it has // transientState, then ListView ill avoid recycling it until the // transientState flag is reset. // A different approach is
Recommends devunwired · 2013-07 · Stack Overflow · on “Why ListView doesn't animate the right item?”
Animating changes with a ListView is a bit trickier than just setting the layout changes flag because of the view recycling that goes on with the Adapter. There is a series of DevBytes articles that Chet Haase has done explaining the issues and how to do this type of thing correctly here. Here is, I think, probably the most relevant one to your predicament. DevBytes: ListView Animations [this video] EDIT I added a second video in that series that may be more helpful, the focus is on delete but the concept is still the same. The key to the trick is adding a ViewTreeObserver.OnPreDrawListener as soon as you add/remove an element in the adapter and trigger notifyDataSetChanged() . The listener will
Recommends Or Bar · 2014-01 · Stack Overflow · on “How to set OnClickListener of a view inside of a custom adapter's getView() without being recycled”
There's a DevBytes video specifically about this problem DevBytes: ListView Animations [this video] It's about having an ongoing animation continue on a recycled view, but the same concept applies to on click listeners
Recommends Stefan Reimers · 2014-09 · Stack Overflow · on “How to Android ListView Scrolling animation in different styles ?”
The DevBytes Videos of Chet Haase and Daniel Olshansky are definitly worth watching when you are thinking about ListView animation. Start here [this video] and click through the videos (on inserting, expanding, deletion animation...). Downloadable resources included, look at [LINK] for download links if not linked in the videos.
Recommends Peter · 2015-03 · Stack Overflow · on “Android animate all listview items simultaneously”
Check out this DevBytes video [this video] about animating ListViews . The solution is to use a StableArrayAdapter [LINK] (direct link to code). This prevents the View objects from being recycled out from under you while you perform your animations. private class StableArrayAdapter extends ArrayAdapter<String> { HashMap<String, Integer> mIdMap = new HashMap<String, Integer>(); public StableArrayAdapter(Context context, int textViewResourceId, List<String> objects) { super(context, textViewResourceId, objects); for (int i = 0; i < objects.size(); ++i) { mIdMap.put(objects.get(i), i); } } @Override public long getItemId(int position) { String item = getItem(position); return mIdMap.get(item); } @Ov
Recommends Peter · 2015-04 · Stack Overflow · on “Android LiistView item update”
The views are being recycled. This DevBytes video on ListView animation [this video] explains exactly what your problem is. It describes how to notify the framework that you don't want a particular view recycled. This is accomplished by calling setHasTransientState() [LINK] on the View in question. For a better solution, check out the StableArrayAdapter from this DevBytes video on animating ListView deletion [LINK] (particularly the first three minutes). The StableArrayAdapter overrides hasStableIds() [LINK] to return true, which has the same effect as setHasTransientState() [LINK] . /* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "L
Recommends EE66 · 2015-06 · Stack Overflow · on “ImageView inside Gridview repeating image when scrolling (using ImageDownloader)”
I would suggest for u to use a library for the image downloading, picasso [LINK] does a great job for it. Another thing take a look at this [this video] video from dev-bytes. Its about animations but the trick should be the same for downloading images. Those two steps should work, I've done that a few times and it worked perfcetly.
Recommends Kartheek · 2015-06 · Stack Overflow · on “Animate addition to android listview?”
Animate each added element in the getView() method of your Custom Adapter. public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; // Your code .............. if(flag == false) { Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_top_to_bottom); v.startAnimation(animation); } return v; } LayoutTransition (introduced in Android 3.0) continues to provide functionality that makes some kinds of animations easier, specifically when adding, removing, hiding, and showing views. For example, either this snippet in a layout file: <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:animateLayoutCha