动画加载方式

Tween动画加载的两种方式:
1, mLeft = (ImageView)findViewById(R.id.imageLeft);
AnimationSet anim = new AnimationSet(true);
TranslateAnimation mytranslateanim = new TranslateAnimation

(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,-

1f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f);
  mytranslateanim.setDuration(2000);
  anim.addAnimation(mytranslateanim);
  anim.setFillAfter(true);
  mLeft.startAnimation(anim);

2,xml中加载的方式:<set xmlns:android="http://schemas.android.com/apk/res/android">
                     <translate
                      android:fromXDelta="10"
                      android:toXDltea="100"
                      android:fromYDelta="10"
                      android:toYDelta="100">
                      </translate>
                     </set>
Animation translateanimation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.my_scale);
imageview.startAnimation(translateanimation);


也有这样的做法:

    <style name="AnimFade" parent="@android:style/Animation.Activity"> 
     <item name="android:activityOpenEnterAnimation">@anim/fade_in</item> 
     <item name="android:activityOpenExitAnimation">@anim/hold</item>       
     <item name="android:activityCloseEnterAnimation">@anim/fade_in</item> 
     <item name="android:activityCloseExitAnimation">@anim/fade_out</item>
 </style>

而:fade_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="0.0" android:toAlpha="1.0"
    android:duration="300" />

你可能感兴趣的:(动画加载方式)