1. 程式人生 > >筆記15 Animation 安卓特效動畫效果 組合動畫

筆記15 Animation 安卓特效動畫效果 組合動畫

實現方式:

Animation loadAnimation = AnimationUtils
      .loadAnimation(this, R.anim.translate);
image.startAnimation(loadAnimation);
final Animation loadAnimation2 = AnimationUtils.loadAnimation(this,
R.anim.rotate);
loadAnimation.setAnimationListener(new AnimationListener() {

   @Override
public void 
onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { }@Override public void onAnimationEnd(Animation arg0) { image.startAnimation(loadAnimation2);//第一個動畫播放完成後在監聽裡呼叫動畫二loadAnimation2} });

實現方式:

Animation loadAnimation = AnimationUtils.loadAnimation
(this, R.anim.continue_anim); image.startAnimation(loadAnimation);

continue_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
android:duration="3000"
android:fromAlpha="0.2"
android:toAlpha="1.0" />
    <alpha
android
:duration="3000" android:fromAlpha="1.0" android:startOffset="3000" android:toAlpha="0.2" /> </set>


AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f);
alphaAnimation.setDuration(100);
alphaAnimation.setRepeatCount(10);
//倒序重複REVERSE  正序重複RESTART
alphaAnimation.setRepeatMode(Animation.REVERSE);
image.startAnimation(alphaAnimation);


實現方式:

Intent intent=new Intent(MainActivity.this,MainActivity2.class);
startActivity(intent);
overridePendingTransition(R.anim.zoom_in,R.anim.zoom_out);

zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
  <scale
android:duration="1000"
android:fromXScale="0.1"
android:fromYScale="0.1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
  <alpha
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1.0" />
</set>

zoom_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top" >
    <scale
android:duration="@android:integer/config_mediumAnimTime"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="0.1"
android:toYScale="0.1" />
    <alpha
android:duration="@android:integer/config_mediumAnimTime"
android:fromAlpha="1.0"
android:toAlpha="0" />
</set>


實現方式:

Intent intent=new Intent(MainActivity.this,ListActivity.class);
startActivity(intent);
ListActivity
package test.ban.com.animation;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListActivity extends Activity{
   
   private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
listView=(ListView) findViewById(R.id.listView);
List<String>list=new ArrayList<String>();
      for(int i=0;i<20;i++)
      {
         list.add("慕課網"+i);
}
      ArrayAdapter<String>adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter);
LayoutAnimationController lac=new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.zoom_in));
lac.setOrder(LayoutAnimationController.ORDER_NORMAL); //載入順序listView.setLayoutAnimation(lac); //listView載入佈局動畫listView.startLayoutAnimation();
}

}
LayoutAnimationController 佈局動畫控制器
lac.setOrder(LayoutAnimationController.ORDER_NORMAL); //載入順序有如下圖三種

zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
  <scale
android:duration="1000"
android:fromXScale="0.1"
android:fromYScale="0.1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
  <alpha
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1.0" />
</set>


實現方式:

private ImageView image;
image = (ImageView) findViewById(R.id.image);
//載入xml檔案實現幀動畫
image.setImageResource(R.drawable.anim_list);   

anim_list.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
android:drawable="@drawable/one"
android:duration="500"/>
    <item
android:drawable="@drawable/two"
android:duration="500"/>
    <item
android:drawable="@drawable/three"
android:duration="500"/>
    <item
android:drawable="@drawable/four"
android:duration="500"/>
    <item
android:drawable="@drawable/five"
android:duration="500"/>
    <item
android:drawable="@drawable/six"
android:duration="500"/>
</animation-list>