Friday, March 16, 2012

[android-developers] ListView row animation not shown because of a bad definition of layout width and height.

Hello,

I have a LinearLayout containing a ListView. My ListView is filled-in with a custom CursorAdapter containing some key - value data.
My database keys are stable, but values randomly changes, and I want to display animations on the ListView rows which value has just changed (flash the background of the TextView) 
I have created and tested the animation. It works fine.
I use cell recycling for my ListView, with the ViewHolder optimization.

Something very strange happens : when I start my application, the first 11 rows of the ListView are shown on the screen. On these elements, my animations are not visible. I can see the values are updated, but the TextView doesn't flash.
When I scroll down the list, the cells from 12 to the end of the list are displaying the animation as expected.

I was fighting with this issue, trying to understand what happens for hours without success. 

I ended up watching this video from Romain Guy and Adam Powell (which, by the way, is great for understanding how to use ListView). At the end of the video, Romain talks about the layout height definition for the list view, that should not be set to wrap_content. So I checked my ListView definition. It has the right fill_parent for both width and eight.
But then, I noticed that the LinearLayout embedding my ListView had defined both width and height to wrap_content (which doesn't make sense in this case).
So I changed it to fill_parent for both width and height, and restart my application.
A there : magic! The animation is started, even for the first elements in the list!!

I'm happy my problem is solved, but I would love to have an expert's explanation on why this happened..

I have tested my code on both emulator and real device, from version 2.1 to 4.0.3.

Regards,
L.P.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment