本文共 1244 字,大约阅读时间需要 4 分钟。
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 object and supply it to the layout with the
method.
If you want to jump ahead and see a full working example, 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
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:
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);}