以编程方式设置 android:animateLayoutChanges
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24054599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting android:animateLayoutChanges programmatically
提问by deimos1988
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?
在 xml 文件中,但由于我以编程方式创建视图,因此我需要以编程方式设置它。我怎样才能做到这一点?
回答by user3709904
Use this code:
使用此代码:
container.setLayoutTransition(new LayoutTransition());
or
或者
LayoutTransition lt = new LayoutTransition();
lt.disableTransitionType(LayoutTransition.DISAPPEARING);
container.setLayoutTransition(lt);
回答by Bob
To disable the fade-out effect try this:
要禁用淡出效果,请尝试以下操作:
LinearLayout layout = (LinearLayout) findViewById(R.id.test_layout);
layout.setLayoutTransition(null);