Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation does not start in ListView items that are currently visible

I'm stuck, and I haven't been able to find a solution for this anywhere. :(

I have an ImageView inside my Layout of each item of my ListView ( GridView ), provided by a BaseAdapter. When the Images are loaded and I assign the loaded BitmapDrawable to the ImageView using

imageView.setImageDrawable( newImage );

the item pops up without any problems.

BUT if I assign the new BitmapDrawable by using a TransitionDrawable OR by assigning a simple Animation:

//this is inoperative - animation will not start for currently displayed items! No solution found :(
Animation a = LibResource.getResourceAnimation( activity, R.anim.fade_in );
imageView.setImageDrawable( newImage );
imageView.startAnimation( a );

The Animation will not start for CURRENTLY DISPLAYED ITEMS of my GridView. If I scroll down the GridView and scroll it back to the mentioned item, the Image is shown and the Animation has been performed!

I've already tried the following fixes:

imageView.invalidateDrawable( newImage );
imageView.invalidate();

I've also tried the following Statements after assigning the Animation - Of course, I called them ON THE UI-Thread, AFTER assigning and starting the Animation ON THE UI-THREAD:

myGridView.invalidate();
myGridView.invalidateViews();
myGridView.getAdapter().notifyDataSetChanged();

As mentioned, this problem only occurs FOR VISIBLE ITEMS in my ListView.

Why does the Animation or TransitionDrawable not start, even after invoking invalidate() etc. on all involved views?

The Problem occurs on my XPeria-Arc-S ( API-Level 10 ) and in the Android-Emulators API-Level 8,9,10.. Is this a bug in the Android System?

Any help would be greatly appreciated!

Thanks in advance

Christopher


Ok - Thanks for your quick reply.

I got the Problem and after a lot of time of reorganizing my code structure for this to work, I came to the point that this did NOT solve my Problem :(.

Beside this, it is NOT applicable or very practical for me to change contents in the creation of the view. Maybe you have any other Solutions regarding this issue?

Sincerely

Christopher

like image 256
Christopher Stock Avatar asked Jun 28 '13 10:06

Christopher Stock


2 Answers

  1. Tell adapter to animate views next time it will be asked for view.
  2. Call invalidateViews().
  3. When getView is called on adapter create view and animate it.
like image 164
Grzegorz Żur Avatar answered Sep 28 '22 09:09

Grzegorz Żur


I've solved this problem.

Starting animations in views for currently visible ListView/GridView-items will not work if you try to assign this Animation to a referenced component of this item.

Instead, you have to invalidate the GridView

myGridView.invalidateViews()

and start the Animation in the according

getView()

method of the connected BaseAdapter.

Though this method is being invoked very often by the system, you normally use a mechanism that caches all views. So if you want to start an Animation in a specific item, you just recreate the view and the next time the system invokes getView() after calling myGridView.invalidateViews(), the animation will start properly!

Thanks to the user who removed his helpful answer.

Greetings Christopher

like image 29
Christopher Stock Avatar answered Sep 28 '22 09:09

Christopher Stock