Setting android:animateLayoutChanges programmatically
39,580
Solution 1
Use this code:
container.setLayoutTransition(new LayoutTransition());
or
LayoutTransition lt = new LayoutTransition();
lt.disableTransitionType(LayoutTransition.DISAPPEARING);
container.setLayoutTransition(lt);
Solution 2
To disable the fade-out effect try this:
LinearLayout layout = (LinearLayout) findViewById(R.id.test_layout);
layout.setLayoutTransition(null);
Author by
deimos1988
Updated on October 14, 2020Comments
-
deimos1988 over 3 years
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?
-
deimos1988 about 10 yearsThank you for your comment, but unfortunately disableTransitionType is only available from API level 16, however I am using API level 15.
-
user3709904 about 10 yearsIt's optional, you can use simply
container.setLayoutTransition(new LayoutTransition())
-
deimos1988 about 10 yearsOkay, but if I wanted to disable the fade-out effect, is there a way for API level 15?
-
Louis CAD over 8 yearsWhy disable disappearing transition?
-
sky over 8 yearsTo do it in api level less than 16, just disable Animators for this transition types. This is mentioned in the documentation: developer.android.com/intl/ru/reference/android/animation/… LayoutTransition lt = cardsGroup.getLayoutTransition(); // disabling appearing / disappearing layout transitions lt.setAnimator(LayoutTransition.APPEARING, null); lt.setAnimator(LayoutTransition.DISAPPEARING, null); lt.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, null);
-
Srujan Barai about 8 yearsThis is giving me NullPointerException.
-
Paul Woitaschek over 7 years@SrujanBarai Then there is no view with the id
R.id. test_layout
in your layout.