此篇主要讲viewgroup中的动画设置,其实很简单,看代码即可
layout = (CascadeLayout) findViewById(R.id. cascade); // 布尔值参数表示所有动画是否使用同一个 interpolator(插补器) AnimationSet set = new AnimationSet( true); AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); alphaAnimation.setDuration(500); set.addAnimation(alphaAnimation); // 参数依次是起始x类型,其实x位置;终点x类型,终点x位置;起始y类型,起始y位置;终点y类型,终点y位置。 TranslateAnimation translateAnimation = new TranslateAnimation( Animation. RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation. RELATIVE_TO_SELF, -1.0f, Animation. RELATIVE_TO_SELF, 0.0f); translateAnimation.setDuration(500); set.addAnimation(translateAnimation); LayoutAnimationController controller = new LayoutAnimationController( set, 0.5f); layout.setLayoutAnimation(controller);
// 偏移位移 int xx = endLocation[0] - startLocation[0]; int yy = endLocation[1] - startLocation[1]; // x方向,平移运动 TranslateAnimation translateAnimation_x = new TranslateAnimation(0, xx, 0, 0); translateAnimation_x.setInterpolator( new LinearInterpolator()); // y方向,加速运动 TranslateAnimation translateAnimation_y = new TranslateAnimation(0, 0, 0, yy); translateAnimation_y.setInterpolator( new AccelerateInterpolator()); // 组合动画 AnimationSet set = new AnimationSet( false); set.addAnimation(translateAnimation_y); set.addAnimation(translateAnimation_x); set.setDuration(1000);