Android 5.0 动画之CircularReveal

5.0的动画非常好看,比过去生硬的界面好看多了,接下来总结一下用到的这个动画,其实很简单,稍作修改,就可以放到我们的项目里进行华丽的过度。

先看布局

<?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"
    android:orientation="vertical"
    tools:context="com.kowalski.circularreveal.MainActivity">

    <ImageView
        android:id="@+id/oval"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="Hello World!"
        android:background="@color/colorPrimary"/>

    <ImageView
        android:id="@+id/rect"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="Hello World!"
        android:background="@color/colorAccent"/>

</LinearLayout>

很简单,定义了两个图片,分别给上不同的背景色。

然后在类里控制动画

package com.kowalski.circularreveal;

import android.animation.Animator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;

public class MainActivity extends Activity
{

    private ImageView oval,rect;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        setViewAction();
    }

    private void initView()
    {
        oval = (ImageView)findViewById(R.id.oval);
        rect = (ImageView)findViewById(R.id.rect);
    }

    private void setViewAction()
    {
        oval.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Animator animator = ViewAnimationUtils.createCircularReveal(oval, oval.getWidth() / 2, oval.getHeight() / 2, oval.getWidth(), 0);
                animator.setInterpolator(new AccelerateDecelerateInterpolator());
                animator.setDuration(2000);
                animator.start();
            }
        });


        rect.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Animator animator = ViewAnimationUtils.createCircularReveal(rect, 0,0,0,(float)Math.hypot(rect.getWidth(),rect.getHeight()));
                animator.setInterpolator(new AccelerateDecelerateInterpolator());
                animator.setDuration(2000);
                animator.start();
            }
        });
    }
}

解释一下动画的方法中的几个参数

public static Animator CreateCircular()
{
    View view, int centerX, int CenterY, float startRadius, float endRadius)
    {
        return new RevealAnimator(view, centerX, centerY, startRadius, endRadius);
    }
}
int centerX: 动画开始的中心点X

int CenterY:动画开始的中心点Y轴

startRadius :动画开始半径

endRadius:动画结束半径

更多优美的动画,大家可以自己尝试。


Demo地址http://download.csdn.net/detail/u012552275/9625566

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值