Android中补间动画3----Animation的监听

来源:互联网 发布:mac地址里ig位 编辑:程序博客网 时间:2024/05/29 16:38

效果图:


Main3Activity
package com.zhh.android;import android.app.Activity;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.animation.Animation;import android.view.animation.LinearInterpolator;import android.view.animation.RotateAnimation;import android.widget.Button;import android.widget.ImageView;/** * 动画监听 */public class Main3Activity extends Activity {    private Button btnScale;    private ImageView ivLauncher;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main3);        initView();        myOnclick();    }    private void initView() {        btnScale = (Button)findViewById(R.id.btnScale);        ivLauncher = (ImageView)findViewById(R.id.ivLauncher);    }    private void myOnclick() {//      按钮点击事件        btnScale.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                setRotateAnimation();            }        });//      图片点击事件        ivLauncher.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                 startActivity(new Intent(Main3Activity.this,Main4Activity.class));            }        });    }    /**     * 旋转动画     */    private void setRotateAnimation(){//        效果以图片中心点为中心,从负90度到正90度,持续5s//        1创建动画对象        RotateAnimation rotateAnimation = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);//        2设置        rotateAnimation.setDuration(5000);//        设置线性变化的插值器(线性变化,加速变化,减速变化,周期循环变化)        rotateAnimation.setInterpolator(new LinearInterpolator());//        动画重复Animation.INFINITE=-1表示无限旋转        rotateAnimation.setRepeatCount(Animation.INFINITE);//        3启动动画        ivLauncher.startAnimation(rotateAnimation);        rotateAnimation.setAnimationListener(new Animation.AnimationListener() {            @Override            public void onAnimationStart(Animation animation) {                Log.e("111","动画开始");            }            @Override            public void onAnimationEnd(Animation animation) {                Log.e("111","动画结束");            }            @Override            public void onAnimationRepeat(Animation animation) {                Log.e("111","动画重复");            }        });    }}
activity_main3.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.zhh.android.Main2Activity"    android:orientation="vertical"    >    <Button        android:id="@+id/btnScale"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="动画的监听事件"        android:textSize="30dp"        />    <ImageView        android:id="@+id/ivLauncher"        android:layout_width="wrap_content"        android:layout_height="200dp"        android:src="@mipmap/cyl"        android:layout_gravity="center_horizontal"        /></LinearLayout>
参考视频:

http://www.gulixueyuan.com/course/112/task/1793/show#

源码下载: