展会信息港展会大全

Animating Layout Changes 动画布局的更改
来源:互联网   发布日期:2015-10-13 15:22:38   浏览:1829次  

导读:A layout animation is a pre-loaded animation that the system runs each time you make a change to the layout configuration. All you need to do is set an attribute in the layout to tell the Android system to animate these layout changes, and...

A layout animation is a pre-loaded animation that the system runs each time you make a change to the layout configuration. All you need to do is set an attribute in the layout to tell the Android system to animate these layout changes, and system-default animations are carried out for you.

Tip: If you want to supply custom layout animations, create a LayoutTransition object and supply it to the layout with the setLayoutTransition() method.

Here's what a default layout animation looks like when adding items to a list: http://blog.csdn.net/sergeycao

If you want to jump ahead and see a full working example, download and run the sample app and select the Crossfade example. See the following files for the code implementation:

src/LayoutChangesActivity.java

layout/activity_layout_changes.xml

menu/activity_layout_changes.xml

Create the Layout

In your activity's layout XML file, set the android:animateLayoutChanges attribute to true for the layout that you want to enable animations for. For instance:

<LinearLayout android:id="@+id/container"

android:animateLayoutChanges="true"

...

/>

Add, Update, or Remove Items from the Layout

Now, all you need to do is add, remove, or update items in the layout and the items are animated automatically:

private ViewGroup mContainerView;

...

private void addItem() {

View newView;

...

mContainerView.addView(newView, 0);

}

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港