首页 > 移动平台 > 详细

animation of android

时间:2015-03-22 16:28:10      阅读:225      评论:0      收藏:0      [点我收藏+]

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?
    }

}

 

animation of android

原文:http://www.cnblogs.com/deman/p/4357455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!