Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layoutAnimation works only one time

I have a LinearLayout with layoutAnimation property that is used for a customize ExpandableListView. like this :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layoutAnimation="@drawable/list_layout_controller"
    android:orientation="vertical" >

When I click on the list, the animation will be displayed. But it works only once and it will not animate the list in the next click. Why?

Please let me know, If you need more description.

Thank you

like image 851
Kermia Avatar asked Apr 15 '12 16:04

Kermia


3 Answers

Layout Animations are run when views are added to the layout. So you will have to manually add/remove the views on every expand/collapse for the layout animation to work.

For this, you can maintain a Map of views with the list index as the key. Every time you get click, just pick the corresponding items from the map and add to your layout. The animation will run on that view and your problem is fixed.

You can also try by changing the visibility of views in onClick(). But not sure about this. Try and let me know.

Hope that helps.

like image 198
Ronnie Avatar answered Oct 18 '22 01:10

Ronnie


First u want to declare

Animation  listanimation = AnimationUtils.loadAnimation(mainActivity.this, R.anim.list_layout_controller);

and everytime clearAnimation first. In clickevent of LinearLayout

 linearLayout.clearAnimation();
 linearLayout.startAnimation(listanimation);
like image 34
Parag Chauhan Avatar answered Oct 18 '22 01:10

Parag Chauhan


call

listView.scheduleLayoutAnimation();

before all changes in the list

like image 3
karabara Avatar answered Oct 18 '22 03:10

karabara