1.首先布局文件里添加Layout布局 display
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<LinearLayout
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:hint="@string/app_name"
android:textColorHint="@color/empty_info_color"
android:lines="5"
android:scrollbars="vertical"
android:singleLine="false"
android:textSize="18sp" />
</LinearLayout>
<ListView
android:id="@+id/list_gps"
android:layout_below="@id/display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<color name="actionbar_tab_text_color">#03a9f4</color>
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroupOverlay;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
private LinearLayout mDisplayView;
mDisplayView = (LinearLayout) findViewById(R.id.display);
3.动画
private void reveal(View sourceView, int colorRes, AnimatorListener listener) {
final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();
final Rect displayRect = new Rect();
mDisplayView.getGlobalVisibleRect(displayRect);
// Make reveal cover the display and status bar.
final View revealView = new View(this);
revealView.setBottom(displayRect.bottom);
revealView.setLeft(displayRect.left);
revealView.setRight(displayRect.right);
revealView.setBackgroundColor(getResources().getColor(colorRes, null));
groupOverlay.add(revealView);
final int[] clearLocation = new int[2];
sourceView.getLocationInWindow(clearLocation);
clearLocation[0] += sourceView.getWidth() / 2;
clearLocation[1] += sourceView.getHeight() / 2;
final int revealCenterX = clearLocation[0] - revealView.getLeft();
final int revealCenterY = clearLocation[1] - revealView.getTop();
final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));
final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
revealCenterY, 0.0f, revealRadius);
revealAnimator.setDuration(500);
final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
alphaAnimator.setDuration(500);
alphaAnimator.addListener(listener);
final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(revealAnimator).before(alphaAnimator);
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
groupOverlay.remove(revealView);
}
});
animatorSet.start();
}
4.执行动画
这里第一个参数是TextView,作为动画的原点
reveal(mTextView, R.color.actionbar_tab_text_color, new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mTextView.setText("");
}
});