animation of android
android 动画方式分两种,渐变动画和帧动画。
渐变动画:给出动画的起止状态,并且通过一定的方式来是view动起来。
帧动画:是给出一组图片,有drawable来展示动画变化过程。
AlphaAnimation:
package com.joyfulmath.animatatorsamples; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.OvershootInterpolator; import android.widget.Button; import android.widget.ImageView; public class AnimationActivity extends Activity implements OnClickListener{ private static final String TAG = "animatatorsamples"; Button mAlphaAnimation = null; ImageView mImage = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_animation_main); mAlphaAnimation = (Button) this.findViewById(R.id.btn_alphaanimation); mAlphaAnimation.setOnClickListener(this); mImage = (ImageView) this.findViewById(R.id.animation_img); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.animation, menu); return true; } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.btn_alphaanimation: startAlphaAnimation(); break; } } private void startAlphaAnimation() { Log.i(TAG, "[startAlphaAnimation]"); AlphaAnimation alphaAni = new AlphaAnimation(1.0f, 0.5f); alphaAni.setDuration(3000); alphaAni.setFillAfter(true); alphaAni.setInterpolator(new OvershootInterpolator()); alphaAni.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub Log.i(TAG, "[onAnimationStart]"); } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub Log.i(TAG, "[onAnimationRepeat]"); } @Override public void onAnimationEnd(Animation arg0) { // TODO Auto-generated method stub Log.i(TAG, "[onAnimationEnd]"); } }); mImage.startAnimation(alphaAni); // mImage.setAnimation(alphaAni); // alphaAni.start();//start? } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。