安卓过渡动画 ViewAnimationUtils简单介绍使用

安卓5.0的过渡动画学习记录一下。效果如图
()
1.方法源码

public static Animator createCircularReveal(View view,
            int centerX,  int centerY, float startRadius, float endRadius) {
        return new RevealAnimator(view, centerX, centerY, startRadius, endRadius);
    }

参数说明:

view:代表的是你要操作的view
centerX:圆的x方向的中点
centerY:圆的y方向的中点
startRadius:这个圆开始时候的半径
endRadius:结束时候的半径

2.示例代码

package com.example.a37443.viewanimationutil;

import android.animation.Animator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img = (ImageView)findViewById(R.id.img);
    }

    public void Onclick(View v){
        switch(v.getId()){
            case R.id.btn_1:
                //对角过渡
                Animator animator = ViewAnimationUtils.createCircularReveal(img,0,0,0, (float) Math.hypot(img.getWidth(), img.getHeight()));
                animator.setDuration(2000);
                animator.start();

                break;
            case R.id.btn_2:
                //中心
                Animator animator2 = ViewAnimationUtils.createCircularReveal(img,img.getWidth()/2,0,0, (float) Math.hypot(img.getWidth(), img.getHeight()));
                animator2.setDuration(1500);
                animator2.start();
                break;
            case R.id.btn_3:
                //从内到外
                Animator animator3 = ViewAnimationUtils.createCircularReveal(img,img.getWidth()/2,img.getHeight()/2,0, img.getWidth());
                animator3.setDuration(2000);
                animator3.start();
                break;
            case R.id.btn_4:
                //从外到内
                Animator animator4 = ViewAnimationUtils.createCircularReveal(img,img.getWidth()/2,img.getHeight()/2,img.getWidth(), 0);
                animator4.setDuration(2000);
                animator4.start();
                break;
            default:
                break;
        }
    }
}

还有其他特效就等待发掘了,学习mark~

猜你喜欢

转载自blog.csdn.net/qq_40571249/article/details/84635299