Android 动画的插值器 (Interpolator属性)
Interpolator(插值器): 属性是设置动画的速度变化的
Interpolator(插值器)的使用方法:
两种方式:在XML 和Java代码中 方法有9中 都是内置的构造方法所以在java代码中使用的时候new 一下 就行了,
不过还是需要知道每个属性的作用下面罗列出来
在java 代码中:
animation.setInterpolator(new AccelerateInterpolator()); // 设置动画为加速动画(动画播放中越来越快)animation.setInterpolator(new DecelerateInterpolator()); // 设置动画为减速动画(动画播放中越来越慢)animation.setInterpolator(new AccelerateDecelerateInterpolator()); // 设置动画为先加速在减速(开始速度最快 逐渐减慢)animation.setInterpolator(new AnticipateInterpolator());// 先反向执行一段,然后再加速反向回来(相当于我们弹簧,先反向压缩一小段,然后在加速弹出)animation.setInterpolator(new AnticipateOvershootInterpolator());// 同上先反向一段,然后加速反向回来,执行完毕自带回弹效果(更形象的弹簧效果)animation.setInterpolator(new BounceInterpolator()); // 执行完毕之后会回弹跳跃几段(相当于我们高空掉下一颗皮球,到地面是会跳动几下)animation.setInterpolator(new CycleInterpolator(2)); // 循环,动画循环一定次数,值的改变为一正弦函数:Math.sin(2* mCycles* Math.PI* input)animation.setInterpolator(new LinearInterpolator()); // 线性均匀改变animation.setInterpolator(new OvershootInterpolator()); // 加速执行,结束之后回弹
在xml 中
android:interpolator="@android:anim/accelerate_interpolator" 设置动画为加速动画(动画播放中越来越快)android:interpolator="@android:anim/decelerate_interpolator" 设置动画为减速动画(动画播放中越来越慢)android:interpolator="@android:anim/accelerate_decelerate_interpolator" 设置动画为先加速在减速(开始速度最快 逐渐减慢)android:interpolator="@android:anim/anticipate_interpolator" 先反向执行一段,然后再加速反向回来(相当于我们弹簧,先反向压缩一小段,然后在加速弹出)android:interpolator="@android:anim/anticipate_overshoot_interpolator" 同上先反向一段,然后加速反向回来,执行完毕自带回弹效果(更形象的弹簧效果)android:interpolator="@android:anim/bounce_interpolator" 执行完毕之后会回弹跳跃几段(相当于我们高空掉下一颗皮球,到地面是会跳动几下)android:interpolator="@android:anim/cycle_interpolator" 循环,动画循环一定次数,值的改变为一正弦函数:Math.sin(2* mCycles* Math.PI* input)android:interpolator="@android:anim/linear_interpolator" 线性均匀改变android:interpolator="@android:anim/overshoot_interpolator" 加速执行,结束之后回弹
下面在java 代码中对各个属性试下效果
java 代码:
public class MainActivity extends AppCompatActivity {private Animation accelerateInterpolator;private Animation decelerateInterpolator;private Animation accelerateDecelerateInterpolator;private Animation anticipateInterpolator;private Animation anticipateOvershootInterpolator;private Animation bounceInterpolator;private Animation cycleInterpolator;private Animation linearInterpolator;private Animation overshootInterpolator;private TextView accelerateInterpolatortv;private TextView decelerateInterpolatortv;private TextView accelerateDecelerateInterpolatortv;private TextView anticipateInterpolatortv;private TextView anticipateOvershootInterpolatortv;private TextView bounceInterpolatortv;private TextView cycleInterpolatortv;private TextView linearInterpolatortv;private TextView overshootInterpolatortv;@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);accelerateInterpolatortv = findViewById(R.id.accelerateInterpolatortv);decelerateInterpolatortv = findViewById(R.id.decelerateInterpolatortv);accelerateDecelerateInterpolatortv = findViewById(R.id.accelerateDecelerateInterpolatortv);anticipateInterpolatortv = findViewById(R.id.anticipateInterpolatortv);anticipateOvershootInterpolatortv = findViewById(R.id.anticipateOvershootInterpolatortv);bounceInterpolatortv = findViewById(R.id.bounceInterpolatortv);cycleInterpolatortv = findViewById(R.id.cycleInterpolatortv);linearInterpolatortv = findViewById(R.id.linearInterpolatortv);overshootInterpolatortv = findViewById(R.id.overshootInterpolatortv);// 设置动画为加速动画(动画播放中越来越快)accelerateInterpolator =AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);accelerateInterpolator.setInterpolator(new AccelerateInterpolator());// 设置动画为减速动画(动画播放中越来越慢)decelerateInterpolator =AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);decelerateInterpolator.setInterpolator(new DecelerateInterpolator());// 设置动画为先加速在减速(开始速度最快 逐渐减慢)accelerateDecelerateInterpolator =AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);accelerateDecelerateInterpolator.setInterpolator(new AccelerateDecelerateInterpolator());// 先反向执行一段,然后再加速反向回来(相当于我们弹簧,先反向压缩一小段,然后在加速弹出)anticipateInterpolator =AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);anticipateInterpolator.setInterpolator(new AnticipateInterpolator());// 同上先反向一段,然后加速反向回来,执行完毕自带回弹效果(更形象的弹簧效果)anticipateOvershootInterpolator = AnimationUtils.loadAnimation(MainActivity.this,R.anim.sacle_shape);anticipateOvershootInterpolator.setInterpolator(new AnticipateOvershootInterpolator());// 执行完毕之后会回弹跳跃几段(相当于我们高空掉下一颗皮球,到地面是会跳动几下)bounceInterpolator = AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);bounceInterpolator.setInterpolator(new BounceInterpolator());// 循环,动画循环一定次数,值的改变为一正弦函数:Math.sin(2* mCycles* Math.PI* input)cycleInterpolator = AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);cycleInterpolator.setInterpolator(new CycleInterpolator(2));// 线性均匀改变linearInterpolator = AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);linearInterpolator.setInterpolator(new LinearInterpolator());// 加速执行,结束之后回弹overshootInterpolator = AnimationUtils.loadAnimation(MainActivity.this, R.anim.sacle_shape);overshootInterpolator.setInterpolator(new OvershootInterpolator());findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {accelerateInterpolatortv.startAnimation(accelerateInterpolator);decelerateInterpolatortv.startAnimation(decelerateInterpolator);accelerateDecelerateInterpolatortv.startAnimation(accelerateDecelerateInterpolator);anticipateInterpolatortv.startAnimation(anticipateInterpolator);anticipateOvershootInterpolatortv.startAnimation(anticipateOvershootInterpolator);bounceInterpolatortv.startAnimation(bounceInterpolator);cycleInterpolatortv.startAnimation(cycleInterpolator);linearInterpolatortv.startAnimation(linearInterpolator);overshootInterpolatortv.startAnimation(overshootInterpolator);}});}}
anim 文件下的sacle_shape 写了一个平移的效果
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="3000"android:fillBefore="true"android:fromXDelta="0"android:fromYDelta="0"android:toXDelta="800"android:toYDelta="0" />
</set>
布局文件
<?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=".MainActivity"><TextViewandroid:id="@+id/accelerateInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="AccelerateInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/decelerateInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="decelerateInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/accelerateDecelerateInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="AccelerateDecelerateInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/anticipateInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="AnticipateInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/anticipateOvershootInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="AnticipateOvershootInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/bounceInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="BounceInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/cycleInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="CycleInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/linearInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="LinearInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><TextViewandroid:id="@+id/overshootInterpolatortv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="5dp"android:text="OvershootInterpolator"android:textColor="@android:color/holo_red_dark"android:textSize="20sp" /><Buttonandroid:id="@+id/btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="开始" /></LinearLayout>
上面9中方法如果感觉不满足需求,可以自定义插值器 (Interpolator属性)
Android 动画的插值器 (Interpolator属性)相关推荐
- [译]Android 动画的灵魂—— Interpolator
本文讲的是[译]Android 动画的灵魂-- Interpolator, 用定制的非线性定时曲线改善你的动画 在现实世界中的运动是非线性的.(当你穿过街道时,你只要略微将你盯着手机的眼睛瞄一眼街道就 ...
- Android 动画效果及Interpolator和AnimationListener的使用
转载http://www.itzhai.com/android-animation-used-to-achieve-control-of-animation-effects-and-use-of-in ...
- Android动画特效之Animator属性动画实现
Android动画特效之自定义view: Android动画特效之自定义view_Angel-杭州的博客-CSDN博客_android view 设置动画 由于上期Android动画特效之自定义Vie ...
- android动画详解二 属性动画原理
property动画是一个强大的框架,它几乎能使你动画任何东西.你可以定义一个动画来改变对象的任何属性,不论其是否被绘制于屏幕之上.一个属性动画在一定时间内多次改变一个属性(对象的一个字段)的值.要动 ...
- android 动画x轴旋转,属性动画Rotation如何以中心轴旋转
//这个是按照某一点进行旋转,默认是view的 ObjectAnimator oaAnimator=ObjectAnimator.ofFloat(imageView1, "rotation& ...
- Android动画之AnimatorSet联合动画用法
动画入门和进阶文章列表: Animation动画概述和执行原理 Android动画之补间动画TweenAnimation Android动画之逐帧动画FrameAnimation Android动画之 ...
- Android动画之LayoutTransition布局动画
动画入门和进阶文章列表: Animation动画概述和执行原理 Android动画之补间动画TweenAnimation Android动画之逐帧动画FrameAnimation Android动画之 ...
- Android动画之逐帧动画FrameAnimation
动画入门和进阶文章列表: Animation动画概述和执行原理 Android动画之补间动画TweenAnimation Android动画之逐帧动画FrameAnimation Android动画之 ...
- Android Interpolator属性 设置动画速度
Android开发中必定会涉及到动画方面的效果,那么就会遇到一个问题,如果控制动画开始速度,与结束速度.还有其他的一些效果 我们可以在xml里面设置属性 复制代码 android:interpolat ...
最新文章
- C++指针与引用的区别
- java 进程消失_Java进程诡异消失问题
- 【并发编程】volatile简单使用
- 一个简单视频网站开发小记
- poj 1015 Jury Compromise_dp
- VC++中Depends工具的使用和DLL函数的动态调用方式示例
- Leetcode 144. 二叉树的前序遍历 (每日一题 20210820)
- 使用Jmeter进行http接口测试
- java word模版填充_[转载]java向word模板中填充数据(总结)
- docker 学习笔记一(教程) 快速上手
- CVPR 2020 论文大盘点-文本图像篇
- github可视化工具_Github标星2.6K!微软开源的可视化工具,未免太酷炫了吧
- php alias 报错,PHP: class_alias - Manual
- Winform 五种常用对话框控件的简单使用
- pythonappium环境搭建_python+appium 环境搭建
- hadoop 编程规范(hadoop专利分析)
- matlab 贝叶斯网络工具箱的安装
- 对2-9取余的计算方法
- 快速学习-cmd命令大全
- .NET(C#) 查找打印机指定打印机名称打印代码(PrintDocument)
热门文章
- 2022-2028年中国集装箱涂料行业市场研究及前瞻分析报告
- kali安装vscode和无法启动解决方法
- 【机器学习】RNN循环神经网络
- CentOS 安装docker.ce报错提示containerd.io >= 1.2.2-3问题
- 安装win下的Anaconda ----针对python3.6.4版本
- android中getMeasuredHeigh()为0的问题
- Java 判断list中是否包含某个元素
- Java清空数组的数据
- Android巩固之事件分发机制
- UIAutomatorViewer、Inspector获取元素信息