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