Android 给layout设置动画的两种方式

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;
}


}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。