当前位置: 代码迷 >> Android >> Android 给layout设立动画的两种方式
  详细解决方案

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

热度:65   发布时间:2016-04-28 01:48:40.0
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;
}


}
  相关解决方案