1,首先我们看一下如下的代码
import android.view.animation.LayoutAnimationController; import android.view.animation.Animation.AnimationListener; import android.view.animation.Transformation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AlphaAnimation; import android.view.animation.TranslateAnimation; private Animation myHistoryAnimation; private LayoutAnimationController myLayoutControl; private AlphaAnimation myHistoryAlphaAnimation; private AlphaAnimation myHistoryAlphaAnimationConTime; private TranslateAnimation myHistoryTranslateAnimation; private AnimationSet myHistoryAnimationSet; myHistoryAlphaAnimation = new AlphaAnimation(1, 0); myHistoryAlphaAnimationConTime = new AlphaAnimation(1, 1); myHistoryAlphaAnimation.setDuration(1000); myHistoryAlphaAnimationConTime.setDuration(500); myHistoryAnimationSet = new AnimationSet(true); /* Vanzo:zhangshuli on: Fri, 20 Mar 2015 14:57:37 +0000 * modify for v5 calculator myHistoryTranslateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation( this, R.anim.history_clear_anim); */ myHistoryTranslateAnimation = new TranslateAnimation( Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,10f); myHistoryTranslateAnimation.setDuration(1000); // End of Vanzo: zhangshuli myHistoryAnimationSet.setFillAfter(true); myHistoryAnimationSet.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub history_clear_choose.setVisibility(View.GONE); } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation arg0) { // TODO Auto-generated method stub android.util.Log.e("zhangshuli", "set"); /* Vanzo:zhangshuli on: Fri, 20 Mar 2015 16:17:24 +0000 * modify for v5 calculator if (mDrawerLayout.isDrawerVisible(GravityCompat.END)) { mDrawerLayout.closeDrawer(GravityCompat.END); } */ // End of Vanzo: zhangshuli } }); myHistoryAlphaAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation arg0) { mHistory.clear(); mLogic.onClear(); android.util.Log.e("zhangshuli", "tran1"); } }); myHistoryAnimationSet.addAnimation(myHistoryTranslateAnimation); myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimation); myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimationConTime); myLayoutControl = new LayoutAnimationController(myHistoryAnimationSet); myLayoutControl.setDelay(0.1f); // myLayoutControl.setOrder(LayoutAnimationController.ORDER_NORMAL); myLayoutControl.setOrder(LayoutAnimationController.ORDER_REVERSE); mHistoryDisplayList.setLayoutAnimation(myLayoutControl);
2.从以上的代码中我们可以发现。代码中定义动画的话,有个好处,就是比较灵活,可以根据我们的需要动态的更改动画的时间等属性。当然,你也会看到它代码的重用性非常的糟糕。
1)创建动画:其实就是new一个相应的动画就行了
2)然后就是设置动画的属性值,时间等
import android.view.animation.AlphaAnimation; AlphaAnimation alphaAnimation=new AlphaAnimation( 1f,0.5f); //动画时间 alphaAnimation.setDuration(1000); //动画结束以后是否应用,false的话,会返回初始位置 alphaAnimation.setFillAfter(true); //设置动画动作样式 alphaAnimation.setInterpolator(this,android.R.anim.accelerate_decelerate_interpolator);
其他的也类似
import android.view.animation.Animation; import android.view.animation.TranslateAnimation; TranslateAnimation translateAnimation = new TranslateAnimation( //第一个参数:相对于父类还是自身比例 第二个其实x坐标 Animation.RELATIVE_TO_SELF, 0f, //起始y坐标 Animation.RELATIVE_TO_SELF,0f, //结束x坐标 Animation.RELATIVE_TO_SELF,0f, //结束y坐标 Animation.RELATIVE_TO_SELF,10f);
3)如果你仅仅就需要一个简单的动画,那么你只需要
时间: 2024-09-30 15:36:44