Android中补间动画2----Animation的基本使用代码实现复合使用

效果图:


Main2Activity
package com.zhh.android;

import android.animation.AnimatorSet;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * 复合动画
 */
public class Main2Activity extends Activity {
    private Button btnScale;
    private ImageView ivLauncher;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        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) {
                setRecombination();
            }
        });
        ivLauncher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Main2Activity.this,Main3Activity.class));
            }
        });
    }

    /**
     * 创建复合动画
     */
    private void setRecombination(){
//     效果:透明度从透明到不透明,持续时间2s,接着旋转360动画,持续1s
//     1创建透明动画,并设置
        AlphaAnimation alphaAnimation = new AlphaAnimation(0f,1f);
        alphaAnimation.setDuration(2000);
//     2创建旋转动画,并设置
        RotateAnimation rotateAnimation = new RotateAnimation(0,360,  Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f);
        rotateAnimation.setDuration(1000);
//      延时两秒
        rotateAnimation.setStartOffset(2000);
//     3创建复合动画对象
        AnimationSet animationSet = new AnimationSet(true);
//     4添加两个动画
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(rotateAnimation);
//     5启动复合动画对象
        ivLauncher.startAnimation(animationSet);
    }


}
activity_main2.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#

源码下载:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值