Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting android:animateLayoutChanges programmatically

I am creating linearLayouts programmatically and would like them to fade in and out when the visibility is set to visible/gone.

I can set

android:animateLayoutChanges="true"  

in the xml-file, but since I am creating the views programmatically, I need to set it programmatically. How can I do that?

like image 339
deimos1988 Avatar asked Jun 05 '14 07:06

deimos1988


2 Answers

Use this code:

container.setLayoutTransition(new LayoutTransition()); 

or

LayoutTransition lt = new LayoutTransition(); lt.disableTransitionType(LayoutTransition.DISAPPEARING); container.setLayoutTransition(lt); 
like image 100
user3709904 Avatar answered Sep 19 '22 20:09

user3709904


To disable the fade-out effect try this:

LinearLayout layout = (LinearLayout) findViewById(R.id.test_layout); layout.setLayoutTransition(null); 
like image 37
Bob Avatar answered Sep 19 '22 20:09

Bob