public class MainActivity extends Activity {
LinearLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
layout = (LinearLayout) findViewById(R.id.layout);
layout.setLayoutAnimation(getAnimationController());//這是第一種方式
// layout.startAnimation(getAnimation());//這是第2種方式
}
protected LayoutAnimationController getAnimationController() {
LayoutAnimationController controller;
// AnimationSet set = new AnimationSet(true);
Animation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);// 從0.5倍放大到1倍
anim.setDuration(1500);
controller = new LayoutAnimationController(anim, 0.1f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
return controller;
}
protected Animation getAnimation() {
Animation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);// 從0.5倍放大到1倍
anim.setDuration(1500);
return anim;
}
}