使用动画实现微信读书的换一批效果(两种方式)
作者:henkun 时间:2023-10-23 14:30:55
先来看看微信读书的效果
实现思路
这个效果比较简单,主要是旋转view,然后在旋转结束后更换view的背景,考虑到需要旋转view,所以使用动画来实现
两种实现方式1.方式一 使用ObjectAnimator结合AnimatorSet
核心过程如下:
创建布局,一个容器,四个view,过程简单,这里不做介绍
创建两个list,一个用来存放动画,一个用来存放view
使用ObjectAnimator创建四个动画,然后将动画放到list中
设置动画监听,动画结束时更换view背景
核心代码如下:
public void startAnimation01(){
animators.clear();
//创建四个动画,每个动画逆时针旋转180度
Animator animator01 = ObjectAnimator.ofFloat(imageView01,"RotationY",0,-180);
Animator animator02 = ObjectAnimator.ofFloat(imageView02,"RotationY",0,-180);
Animator animator03 = ObjectAnimator.ofFloat(imageView03,"RotationY",0,-180);
Animator animator04 = ObjectAnimator.ofFloat(imageView04,"RotationY",0,-180);
animators.add(animator01);
animators.add(animator02);
animators.add(animator03);
animators.add(animator04);
//循环中统一处理事件监听,动画结束时更换每个view的背景
for(int i=0;i<animators.size();i++){
final int finalI = i;
animators.get(i).addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
//更换背景
imageViews.get(finalI).setBackgroundColor(Color.parseColor("#FFAEB9"));
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
AnimatorSet set = new AnimatorSet();
//集合中的动画会顺序执行
set.playSequentially(animators);
set.setStartDelay(200);
set.setDuration(300);
set.start();
}
2. 方式二 使用ViewPropertyAnimator
上面的方法使用的ObjectAnimator来实现,ObjectAnimator的缺点就是实现起来代码量比较大,重复的东西比较多。ViewPropertyAnimator可以以少量代码实现效果,简介明了。
核心代码如下:
public void startAnimation02(){
for (int i=0;i<animators01.size();i++){
final int finalI = i;
animators01.get(i).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
imageViews.get(finalI).setBackgroundColor(Color.parseColor("#FFAEB9"));
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}
一开始使用的rotationY,但是rotationY从效果上看只能执行一次(其实是每次都会执行,只是没有变化而已),而rotationYBy则可以重复多次执行。其他属性也是同样的效果。
效果展示
来源:https://blog.csdn.net/henkun/article/details/106036052
标签:微信,读书,换一批
0
投稿
猜你喜欢
mysql表的性能提升的相关问题
2010-03-03 16:31:00
网页版权的正确写法
2007-09-22 09:13:00
浅析python中的分片与截断序列
2022-05-11 02:31:03
CentOS+Nginx+PHP+MySQL详细配置(图解)
2023-11-24 03:04:13
Python 读取千万级数据自动写入 MySQL 数据库
2023-11-08 09:25:47
python 缺失值处理的方法(Imputation)
2023-03-04 11:09:14
在ASP.NET2.0通过SMTP的验证发送EMAIL
2007-09-23 12:29:00
浅析python中的迭代与迭代对象
2023-11-19 09:21:35
python中join与os.path.join()函数实例详解
2023-08-23 19:20:51
Python 实现王者荣耀中的敏感词过滤示例
2023-08-14 01:21:04
解决pyshp UnicodeDecodeError的问题
2021-08-01 10:17:39
Python中pass的作用与使用教程
2023-05-05 23:05:05
Python中collections.Counter()的具体使用
2023-04-22 23:26:35
asp如何设置cookie的过期时间
2008-02-29 13:36:00
Python逐行读取文件中内容的简单方法
2023-03-02 16:01:09
Django原生sql也能使用Paginator分页的示例代码
2023-11-09 10:00:06
python多线程semaphore实现线程数控制的示例
2022-12-29 18:31:40
使用Django和Python创建Json response的方法
2022-04-28 13:08:42
NCCL深度学习Bootstrap网络连接建立源码解析
2022-02-25 22:28:10
ThinkPHP CURD方法之limit方法详解
2023-11-15 03:58:00