介绍
官方文档
介绍,可以看出是5.0新出的新特性
Defines common utilities for working with View's animations.
译:
定义:用于处理View动画的常用工具
成员变量和方法
公开方法从文档中可以看出只有一个公开的方法:
createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius)
简单介绍一下参数:
view :The View will be clipped to the animating circle. 即:要想裁剪为圆形的View
centerX: 相对于视图来说,动画圆的中心的x坐标。
centerY:相对于视图来说,动画圆的中心的y坐标。
startRadius : 动画圆开始的半径。
endRadius :动画圆结束的半径。
return Animator 该方法返回一个Animator对象
如何使用
Animator circularReveal = ViewAnimationUtils.createCircularReveal(ivAvauImg, 0, btnHeight, 0, mSceenHeight);
circularReveal.setDuration(2000);
circularReveal.start();
Demo
pre.gif具体的代码如下:
public class ViewAnimationUtilsActivity extends AppCompatActivity {
@InjectView(R.id.btn_avau_left_top)
Button btnAvauLeftTop;
@InjectView(R.id.btn_avau_right_top)
Button btnAvauRightTop;
@InjectView(R.id.btn_avau_center)
Button btnAvauCenter;
@InjectView(R.id.btn_avau_bottom)
Button btnAvauBottom;
@InjectView(R.id.iv_avau_img)
ImageView ivAvauImg;
@InjectView(R.id.iv_avau_icon)
ImageView ivAvauIcon;
private int imgWidth;
private int imgHeight;
private int mSceenHeight;
private int mSceenWidth;
private int btnHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_animation_utils);
ButterKnife.inject(this);
imgWidth = ivAvauImg.getWidth();
imgHeight = ivAvauImg.getHeight();
mSceenHeight = getResources().getDisplayMetrics().heightPixels;
mSceenWidth = getResources().getDisplayMetrics().widthPixels;
btnHeight = btnAvauBottom.getHeight();
}
@OnClick({R.id.btn_avau_left_top, R.id.btn_avau_right_top, R.id.btn_avau_center, R.id.btn_avau_bottom})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.btn_avau_left_top:
Animator circularReveal = ViewAnimationUtils.createCircularReveal(ivAvauImg, 0, btnHeight, 0, mSceenHeight);
circularReveal.setDuration(2000);
circularReveal.start();
break;
case R.id.btn_avau_right_top:
Animator animator = ViewAnimationUtils.createCircularReveal(ivAvauImg, mSceenWidth, btnHeight, 0, mSceenHeight);
animator.setDuration(2000);
animator.start();
break;
case R.id.btn_avau_center:
Animator animator2 = ViewAnimationUtils.createCircularReveal(ivAvauImg, mSceenWidth / 2, mSceenHeight / 2, mSceenHeight, 80);
animator2.setDuration(5000);
animator2.start();
break;
case R.id.btn_avau_bottom:
final Animator animator3 = ViewAnimationUtils.createCircularReveal(ivAvauImg, mSceenWidth / 2, mSceenHeight-3*btnHeight, mSceenHeight, 80);
animator3.setDuration(2000);
animator3.start();
animator3.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
ivAvauImg.setVisibility(View.GONE);
ivAvauIcon.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
break;
}
}
}
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
tools:context="com.example.linsa.retrofitdemo.activity.ViewAnimationUtilsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_avau_left_top"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="左上"/>
<Button
android:id="@+id/btn_avau_right_top"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="右上"/>
<Button
android:id="@+id/btn_avau_center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="中心"/>
<Button
android:id="@+id/btn_avau_bottom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="底部"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_avau_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/img4"/>
<ImageView
android:id="@+id/iv_avau_icon"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="bottom|center"
android:visibility="gone"
android:src="@mipmap/icon_head"/>
</FrameLayout>
</LinearLayout>
网友评论