根据之前所学的所有动画,我们都可以在不同的实例中将动画效果添加进去,让界面更灵活美观,下面我就用一个简单的ListView来实现添加动画效果:
一、要实现的效果:
- 一组ListView数组,当打开页面的时候,ListView上所有的数据以渐进缩放动画效果呈现出来;
二、效果图:
package com.example.examples_scaleanimation;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.animation.LayoutAnimationController;
import android.view.animation.ScaleAnimation;
import android.widget.ArrayAdapter;
public class MainActivity extends ListActivity {
private ArrayAdapter<String> adapter;
private LayoutAnimationController lac;
private ScaleAnimation sa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
new String[]{"缩进ListView","缩进ListView","缩进ListView","缩进ListView",
"缩进ListView","缩进ListView","缩进ListView","缩进ListView","缩进ListView",
"缩进ListView","缩进ListView","缩进ListView"});
setListAdapter(adapter);
sa=new ScaleAnimation(0,1,0,1);
sa.setDuration(1000);
/*
* 参数:animation the animation to use on each child of the view group
delay the delay by which each child's animation must be offset
*/
lac=new LayoutAnimationController(sa, 0.5f);
getListView().setLayoutAnimation(lac);
}
}