补间动画 旋转 平移 缩放 透明

package com.example.rk_02;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;


/**
 * A simple {@link Fragment} subclass.
 */
public class BlankFragment extends Fragment {
    private View view;
    private ImageView imageView;
    private Button btn01, btn02,btn03,btn04;
    private TranslateAnimation translateAnimation;
    private RotateAnimation rotateAnimation;
    private ScaleAnimation scaleAnimation;
    private AlphaAnimation alphaAnimation;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_blank, container, false);
        ;
        imageView = (ImageView) view.findViewById(R.id.iv);
        btn01 = (Button) view.findViewById(R.id.btn01);
        btn02 = (Button) view.findViewById(R.id.btn02);
        btn03= (Button) view.findViewById(R.id.btn03);
        btn04= (Button) view.findViewById(R.id.btn04);
        //旋转
        btn01.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                rotateAnimation.setDuration(2000);
                rotateAnimation.setRepeatCount(1);
                rotateAnimation.setRepeatMode(Animation.REVERSE);
                rotateAnimation.setFillAfter(true);
                imageView.startAnimation(rotateAnimation);
            }
        });
        //透明
        btn02.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alphaAnimation = new AlphaAnimation(0, 1);
                alphaAnimation.setDuration(2000);
                alphaAnimation.setRepeatCount(1);
                alphaAnimation.setRepeatMode(Animation.REVERSE);
                imageView.startAnimation(alphaAnimation);
            }
        });
        btn03.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 2
                        , Animation.RELATIVE_TO_SELF, -0.5f, Animation.RELATIVE_TO_SELF, 1.5f);
                translateAnimation.setDuration(2000);
                translateAnimation.setRepeatCount(1);
                translateAnimation.setRepeatMode(Animation.REVERSE);
                imageView.startAnimation(translateAnimation);
            }
        });

        //放大
        btn04.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                scaleAnimation = new ScaleAnimation(0.5f, 2, 0.1f, 3, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                scaleAnimation.setDuration(2000);
                scaleAnimation.setRepeatCount(1);
                scaleAnimation.setRepeatMode(Animation.ABSOLUTE);
                scaleAnimation.setFillAfter(true);
                imageView.setAnimation(scaleAnimation);
            }
        });
        return view;
    }

    public void fly(View view) {
        AnimationSet set = new AnimationSet(false);
        set.addAnimation(translateAnimation);
        set.addAnimation(alphaAnimation);
        set.addAnimation(scaleAnimation);
        set.addAnimation(rotateAnimation);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值