android今日头条刷新,仿今日头条刷新vector动画

一般的刷新动画是一个圈圈在转,而头条的比较特殊,直接上写好的效果图(一直不知道怎么把图片尺寸调小o(╯□╰)o)吧~

fba2ffb8335e

刷新动画_.gif

首先整个效果是通过SVG和vector来实现的,如果不是很了解,请看大佬的文章:

SVG学习--AnimatedVectorDrawable的使用

动画思路:

整个view可以分为五个部分:

1、最外面的壳(不需要动画)

2、中间矩形框

3、矩形框中的灰色矩形块

4、三根短线

5、三根长线

第一步:在drawable文件夹下新建名为refresh的vector文件:

android:width="200dp"

android:height="200dp"

android:viewportHeight="200"

android:viewportWidth="200">

android:name="out_rect"

android:pathData="M70,60

L130,60

Q140,60 140,70

L140,130

Q140,140 130,140

L70,140

Q60,140 60,130

L60,70

Q60,60 70,60"

android:strokeColor="@color/colorCustomHeaderLine"

android:strokeWidth="2" />

android:name="middle_rect"

android:pathData="M71,75

L100,75

L100,95

L72,95

L72,75"

android:strokeColor="@color/colorCustomHeaderLine"

android:strokeWidth="2" />

android:name="inner_rect"

android:fillColor="@color/colorCustomHeaderInner"

android:pathData="M73,76

L99,76

L99,94

L73,94" />

android:name="short_lines"

android:pathData="M108,75

L128,75

M108,85

L128,85

M108,95

L128,95"

android:strokeColor="@color/colorCustomHeaderLine"

android:strokeWidth="2" />

android:name="long_lines"

android:pathData="

M72,105

L128,105

M72,115

L128,115

M72,125

L128,125"

android:strokeColor="@color/colorCustomHeaderLine"

android:strokeWidth="2" />

打开xml右边的预览,我们可以看到效果

fba2ffb8335e

效果图.png

第二步:在drawable文件夹下新建名为refresh_vector的animated-vector

android:drawable="@drawable/refresh">

android:name="middle_rect"

android:animation="@animator/anim_middle_rect" />

android:name="short_lines"

android:animation="@animator/anim_short_lines" />

android:name="long_lines"

android:animation="@animator/anim_long_lines" />

android:name="inner_rect"

android:animation="@animator/anim_inner_rect" />

这里需要注意几点:

1、android:drawable="@drawable/refresh"这里一定要引用上面的refresh文件

2、target标签下的name一定要和refresh中的path标签下的名字一致

第三步:新建animator文件夹(不是anim),并在下面新建短线、长线、中间矩形框和里面矩形对应的objectAnimator集合:

anim_middle_rect.xml:

android:ordering="sequentially">

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M71,75

L100,75

L100,95

L72,95

L72,75"

android:valueTo="M99,75

L128,75

L128,95

L100,95

L100,75"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M99,75

L128,75

L128,95

L100,95

L100,75"

android:valueTo="M99,105

L128,105

L128,125

L100,125

L100,105"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M99,105

L128,105

L128,125

L100,125

L100,105"

android:valueTo="M71,105

L100,105

L100,125

L72,125

L72,105"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M71,105

L100,105

L100,125

L72,125

L72,105"

android:valueTo="M71,75

L100,75

L100,95

L72,95

L72,75"

android:valueType="pathType" />

anim_short_lines.xml:

android:ordering="sequentially">

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M108,75

L128,75

M108,85

L128,85

M108,95

L128,95"

android:valueTo="M72,105

L128,105

M72,115

L128,115

M72,125

L128,125"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M72,105

L128,105

M72,115

L128,115

M72,125

L128,125"

android:valueTo="M72,105

L92,105

M72,115

L92,115

M72,125

L92,125"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M72,105

L92,105

M72,115

L92,115

M72,125

L92,125"

android:valueTo="M72,75

L128,75

M72,85

L128,85

M72,95

L128,95"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M72,75

L128,75

M72,85

L128,85

M72,95

L128,95"

android:valueTo="M108,75

L128,75

M108,85

L128,85

M108,95

L128,95"

android:valueType="pathType" />

anim_long_lines.xml:

android:ordering="sequentially">

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M72,105

L128,105

M72,115

L128,115

M72,125

L128,125"

android:valueTo="M72,75

L92,75

M72,85

L92,85

M72,95

L92,95"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M72,75

L92,75

M72,85

L92,85

M72,95

L92,95"

android:valueTo="M72,75

L128,75

M72,85

L128,85

M72,95

L128,95"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M72,75

L128,75

M72,85

L128,85

M72,95

L128,95"

android:valueTo="M108,105

L128,105

M108,115

L128,115

M108,125

L128,125"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M108,105

L128,105

M108,115

L128,115

M108,125

L128,125"

android:valueTo="M72,105

L128,105

M72,115

L128,115

M72,125

L128,125"

android:valueType="pathType" />

anim_inner_rect.xml

android:ordering="sequentially">

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M73,76

L99,76

L99,94

L73,94"

android:valueTo="M101,76

L127,76

L127,94

L101,94"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M101,76

L127,76

L127,94

L101,94"

android:valueTo="M101,106

L127,106

L127,124

L101,124"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M101,106

L127,106

L127,124

L101,124"

android:valueTo="M73,106

L99,106

L99,124

L73,124"

android:valueType="pathType" />

android:duration="500"

android:interpolator="@android:interpolator/decelerate_cubic"

android:propertyName="pathData"

android:valueFrom="M73,106

L99,106

L99,124

L73,124"

android:valueTo="M73,76

L99,76

L99,94

L73,94"

android:valueType="pathType" />

最后一步,在activity中:

android:id="@+id/imageView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

final AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.refresh_vector);

findViewById(R.id.imageView).setImageDrawable(animatedVectorDrawable);

animatedVectorDrawable.start();

//循环动画貌似只能这样。。。

final Handler mainHandler = new Handler(Looper.getMainLooper());

animatedVectorDrawable.registerAnimationCallback(new Animatable2.AnimationCallback() {

@Override

public void onAnimationEnd(Drawable drawable) {

mainHandler.post(new Runnable() {

@Override

public void run() {

animatedVectorDrawable.start();

}

});

}

});

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/526940.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

android懒加载单实例,【 Android 10 设计模式 】系列 -- 单例

前言由于源码分析的代码量比较大,大部分博客网站的内容显示页面都比较窄,显示出来的效果都异常丑陋,所以您也可以直接查看 《 Thinking in Android 》 来阅读这边文章,希望这篇文章能帮你梳理清楚 “ 单例模式 ”。一、概述1.1 什…

android资产目录,android – 从非目录设备中的资产文件夹复制数据库

我正在尝试从资产文件夹将数据库复制到设备.此代码在模拟器和根设备上正常工作.我只是想知道是否在无人看管的设备上创建任何问题,否则它会相同.private void StoreDatabase() {File DbFile new File("data/data/packagename/DBname.sqlite");if (DbFile.exists()) …

在html中标题字号一共有几种,HTML中常用的几种标签

在HTML中,标签是首要的,也是最重要的东西。一旦进入HTML,认识和理解标签是基本的需要,因为这是区分HTML代码与普通文本的分隔符。这些标签是用来显示文档中的普通文本或转化文本的指令的标签。什么是转化后的文本?要显…

html静态页面引用其他页面,Shtml完美解决静态页面内部调用其他页面(非Iframe、Object、Js方法)...

我想这个是所有前端工程师都会碰到的问题,在你做了很多页面,需要调用同一个头部或者底部的时候,需要嵌套一下,这个时候怎么办Iframe、Object、Js调用的方法就不讨论了,网上搜索一大堆,不过兼容性不好这里给…

鸿蒙手机如何录屏,安卓手机如何屏幕录制视屏?手机视频录制方法

安卓手机如何屏幕录制视屏?手机视频录制方法2018年12月17日 17:05作者:黄页编辑:黄页分享随着科技的不断进步发展,手机已经成为人类不可缺少的一种生活神器,人们已经不满足只是用来打打电话、发发短信那么简单了,手机的用途主要用来社交、娱乐…

html判断为空的函数,javascript怎么判断是否为空字符串?

JavaScript中可以使用if(typeof obj"undefined"||objnull||obj"")语句通过判断字符串的数据类型来判断字符串是否为空。判断字符串是否为空的方法函数:function isEmpty(obj){if(typeof obj "undefined" || obj null || obj "…

html或原生js是单一对应绑定的,原生js数据绑定

双向数据绑定是非常重要的特性 —— 将JS模型与HTML视图对应,能减少模板编译时间同时提高用户体验。我们将学习在不使用框架的情况下,使用原生JS实现双向绑定 —— 一种为Object.observe_(译注:现已废弃,作者写博客时为14年11月)&…

et200sp模块接线手册_西门子PN/PN耦合器学习应用系列(1)-外观及接线

早在2017年我曾写过两篇文章介绍西门子PN/PN耦合器,文章链接如下:初识西门子PNPN耦合器(PN/PN Coupler);如何在博途(TIA Portal)环境下组态PNPN耦合器?当时PN/PN耦合器的固件版本还是V3.x。随着产品的升级,新版本的PN/…

textview加载html glide,TextView加载HTML,文字和图片

原文出处链接:《TextView加载HTML,文字和图片》工具类:public class ImageGetterUtils {public static MyImageGetter getImageGetter(Context context, TextView textView) {MyImageGetter myImageGetter new MyImageGetter(context, textV…

js 条码枪扫描_年会展台 精彩不断 | 沧田:从打印到扫描录入 国产品牌从未停止...

11月23日-25日,中国现代办公行业年会(以下简称COAA年会)在南昌召开。今年对于OA行业而言,国产品牌的崛起成为主要特征之一。以针式打印机起家的沧田,在本次展会中展示了多款重量级产品,涵盖了针式打印机、激光一体机、条码打印机、…

投后管理岗面试_2020天津水务招79人,管理岗+操作岗,专科起报

Hello大家好,我们今天的国企招聘主要说的是天津水务。天津水务的公告和去年相比晚了几个月,而且要求也变了一些——变成了校招(要求2020年应届生),虽然条件还是不高——大专起报。2点要求基本的条件就是要求&#xff1…

html的课设作业6,第七节课html标签元素属性作业-2019-9-6 作业

实例html>2019最新课程表table {/* border: 1px solid #000; *//* border-collapse: collapse; */width: 800px;margin: 2px auto;border-spacing: 0;/* box-shadow: 2px 2px 2px #888888; */}th,td {/* border: 1px solid #000; */text-align: center;padding: 10px;border…

微信没有回车键怎么换行_在东平相亲网加了心仪对方的微信,但是没有话题怎么办?...

最近很多东平单身小伙伴问红娘:加了对方微信不知道聊什么,觉得两个人没有共同话题,而且感觉该聊的都聊了,每天早晚安也发了,够热情了。还有的说不知道怎么回信息或者不知道跟ta说什么话题该怎么办?1其实这些…

中国重汽微服务管理_springcloud微服务架构实战:商家管理微服务设计

商家管理微服务设计商家管理微服务是一个独立的RESTAPI应用,这个应用通过接口服务对外提供商家信息管理、商家权限管理和菜单资源管理等方面的功能。商家管理微服务开发在merchant-restapi模块中实现,有关这一类型模块的依赖引用、配置、启动程序的设计等…

计算机自带游戏在哪里打开,电脑自带游戏选项在哪里打开

如果只是这个游戏有这个问题,就是软件有问题了,重装这游戏,如果有好几个软件都有这个问题,无疑是中毒了,用360彻底查杀。不行重装系统,装完后马上装360,再升级查杀。重装游戏。不行就-------那是…

html文字竖直书写,css 文字竖直居中的写法和图片垂直居中代码(图文)

界面上文章左右居中使用text-aligin:center,上下竖直居中的写法如下,图片垂直居中的代码文字、图片居中显示的方法.content{height: 40px;line-height: 40px;border:1px double #abc;}.myimg{/*非IE的主流浏览器识别的垂直居中的方法*/display: table-ce…

怎么判断到了月初_双春年与无春年怎么区分?2021年是寡妇年吗?

导读:双春年与无春年怎么区分?2021年是什么春年?就在昨天,我写了一篇关于寡妇年的文章,没想到大家热情高涨,关注度挺高的,还有的朋友私信问我这个双春年、有春年和无春年该怎么分,今…

微型计算机中的奔四指的是,2015云南省计算机等级考试二级理论考试试题及答案...

1、在微型计算机中,微处理器的主要功能是进行( D )A、算术运算 B、逻辑运算C、算术逻辑运算 D、算术逻辑运算及全机的控制2、下列各进制数中最小的数是( A )A、101001B B、520 C、2BH D、44D3、通常,在微机中标明的P4或奔腾4是指( D )A、产品型号 B、主频…

乐橙本地录像回放不了_乐橙智能锁来告诉你:你家门真的安全吗?

你家门锁真的安全吗?你以为家门反锁就没事了?最近,看到一则新闻:女主人反锁门后出门喝喜酒,回家后发现家中遭窃,现金、珠宝首饰等全部遗失。还有那些专门行窃的小偷,他们会先按下房间门铃&#…

swift html编辑器,SwiftUI 的可视化编辑工具

原标题:SwiftUI 的可视化编辑工具作者:希德,iOS 开发者,前“有经验的前端开发工程师”,就职于网易严选。正在写书《Thinkable SwiftUI》(严重拖稿中)Session 10185: https://developer.apple.com/videos/play/wwdc2020…