技术标签: Android开发相关 view java android
Android SVG动画详细例子
老规矩,效果实现有源码
在之前发了一篇关于SVG动画的文章,有小伙伴反应了一些问题,所以出一篇较为详细的动画例子文章,希望有所帮助。
文章链接:Android利用SVG实现动画效果
具体准备工作,请看链接
小提:在写动画文件时, android:propertyName=“trimPathStart” 词别写错了,End也是,如果写成小写会爆异常。
也可用Android自带。
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="73.51dp"
android:height="73.51dp"
android:viewportWidth="73.51"
android:viewportHeight="73.51">
<path
android:fillColor="#fcd765"
android:pathData="M35.67,33.93s-8.5-6.22-4.85-17.76S34.13,28.61,35.67,33.93Z" />
<path
android:fillColor="#fcd765"
android:pathData="M35,33.93S19,31.48,19.9,17.83,29.68,32.9,35,33.93Z" />
<path
android:fillColor="#fcd765"
android:pathData="M31.48,34S16.28,43.59,11,26.54,26.36,36.91,31.48,34Z" />
<path
android:fillColor="#fcd765"
android:pathData="M38.73,33.1s8.5-6.22,4.84-17.77S40.27,27.78,38.73,33.1Z" />
<path
android:fillColor="#fcd765"
android:pathData="M37,34s4-12.79 0.61 -18.48C33.46,8.75,36.57,26.94,37,34Z" />
<path
android:fillColor="#fcd765"
android:pathData="M39.43,33.1s16-2.45,15.07-16.1S44.71,32.07,39.43,33.1Z" />
<path
android:fillColor="#fcd765"
android:pathData="M42.92,33.19s15.2,9.56,20.43-7.48S48,36.08,42.92,33.19Z" />
<path
android:strokeColor="#000"
android:strokeWidth="1"
android:strokeMiterLimit="10"
android:pathData="M38.1,36.69S35.78,53.26,45.36,62.3" />
</vector>
给每个path加上与动画绑定的属性: 如:android:name="leaf1"
完整代码如下(hua.xml):
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="73.51dp"
android:height="73.51dp"
android:viewportWidth="73.51"
android:viewportHeight="73.51">
<path
android:name="leaf1"
android:fillColor="#fcd765"
android:pathData="M35.67,33.93s-8.5-6.22-4.85-17.76S34.13,28.61,35.67,33.93Z" />
<path
android:name="leaf2"
android:fillColor="#fcd765"
android:pathData="M35,33.93S19,31.48,19.9,17.83,29.68,32.9,35,33.93Z" />
<path
android:name="leaf3"
android:fillColor="#fcd765"
android:pathData="M31.48,34S16.28,43.59,11,26.54,26.36,36.91,31.48,34Z" />
<path
android:name="leaf4"
android:fillColor="#fcd765"
android:pathData="M38.73,33.1s8.5-6.22,4.84-17.77S40.27,27.78,38.73,33.1Z" />
<path
android:name="leaf5"
android:fillColor="#fcd765"
android:pathData="M37,34s4-12.79 0.61 -18.48C33.46,8.75,36.57,26.94,37,34Z" />
<path
android:name="leaf6"
android:fillColor="#fcd765"
android:pathData="M39.43,33.1s16-2.45,15.07-16.1S44.71,32.07,39.43,33.1Z" />
<path
android:name="leaf7"
android:fillColor="#fcd765"
android:pathData="M42.92,33.19s15.2,9.56,20.43-7.48S48,36.08,42.92,33.19Z" />
<path
android:name="root"
android:strokeColor="#000"
android:strokeWidth="1"
android:strokeMiterLimit="10"
android:pathData="M38.1,36.69S35.78,53.26,45.36,62.3" />
</vector>
本案例用的一个动画文件,也可用多个。
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:propertyName="trimPathStart"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType">
</objectAnimator>
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:drawable="@drawable/hua">
<target
android:animation="@animator/svg_pathanim"
android:name="leaf1"></target>
<target
android:animation="@animator/svg_pathanim"
android:name="leaf2"></target>
<target
android:animation="@animator/svg_pathanim"
android:name="leaf3"></target>
<target
android:animation="@animator/svg_pathanim"
android:name="leaf4"></target>
<target
android:animation="@animator/svg_pathanim"
android:name="leaf5"></target>
<target
android:animation="@animator/svg_pathanim"
android:name="leaf6"></target>
<target
android:animation="@animator/svg_pathanim"
android:name="leaf7"></target>
<target
android:animation="@animator/svg_pathanim"
android:name="root"></target>
</animated-vector>
<ImageView
android:id="@+id/iv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
app:srcCompat="@drawable/hua_anim" />
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView anim_path;
private Drawable drawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
anim_path = (ImageView) findViewById(R.id.iv);
anim_path.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.iv:
startAnim(anim_path);
break;
}
}
/**
* 启动动画
*
* @param iv
*/
private void startAnim(ImageView iv) {
drawable = iv.getDrawable();
if (drawable instanceof Animatable) {
((Animatable) drawable).start();
}
}
}
文章浏览阅读436次,点赞15次,收藏2次。原因或许是,使用autofocus时,确实聚焦了!但是当我们又点击 显示弹出框的按钮时,input又失焦了,所以当我们看到input框时,没有自动聚焦。_vue3 el-input 自动聚焦autofocus无效
文章浏览阅读222次。《《说课稿LINUX》PPT课件.ppt》由会员分享,可在线阅读,更多相关《《说课稿LINUX》PPT课件.ppt(16页珍藏版)》请在装配图网上搜索。1、LINUX 基础应用与配置管理 桂林山水职业学院计算机系 朱笑雷 主要内容 课程定位 1 课程内容设置 2 教学方法与手段 3 教材建设 4 教学团度 5 主要内容 实践条件 6 课程考核 7 教学效果 8 课程特色 9 建设思路 10 一、课..._linux说课课件
文章浏览阅读2.2k次。#在SpringBoot中启动时关于连接数据库失败的问题对照了application.yml,发现配置文件貌似没什么问题,但是在查找信息之后,发现问题正是出现在application.yml中问题出于datasource下的data-username和data-password只要将data-username和data-password改为username和password即可..._springboot启动时数据库连接失败 不关闭
文章浏览阅读4.6k次。一般情况下登录系统后菜单是由后端返回的,不是前端写死的。antd-pro也支持,修改的路径在app.tsx在 layout 里加一个menuDataRender字段先给一个() =>[]可以看到左侧菜单没了,说明配置生效了,接下来就可以围绕这个配置做文章了,我们先定义一个 menuDataRender方法。根据登录缓存到本地的数据做下处理,判断菜单里要展示哪些内容(比如替换字段,隐藏不显示的菜单,隐藏按钮等),处理好了后返回一个数组结构即可。示例代码如下export const layout: _antdpro的菜单
文章浏览阅读77次。为什么80%的码农都做不了架构师?>>> ..._jprofiler6 key
文章浏览阅读170次。(可以看出递归算法更加侧重于计算的技巧,并且计算机计算的次数也相对更少);_c语言程序设计第四版课后题答案苏小红第七章
文章浏览阅读4.4w次,点赞8次,收藏51次。浏览器抓包(工具:fiddler)并 修改请求内容 工具下载:https://pan.baidu.com/s/1pyKdAwgTdNNvoWA2bGlk9A 1、正常打开网页,输入要提交的内容 2、打开工具,f11暂停了页面的所有提交动作 3、这时再点击提交按钮,请求的数据就会被工具拦截 4、双击截取的数据,右侧会看到请求的具体内容,任意修改数据 5、点击绿色按钮 run ..._filder改数据包
文章浏览阅读560次。如果您想在计算机或任何其他设备上播放高质量的视频,高清视频转换器可以帮助确保您的视频与您的操作系统和硬件兼容。您还可以使用高清转换器更改视频的分辨率,无论您是想提高质量还是降低分辨率以生成更小的文件。在下表中,我们描述了用于转换高清视频的最流行和可用的桌面程序和在线服务。它们各有优缺点,因此请根据您的需要进行选择。_奇客视频转换
文章浏览阅读1.9k次。欢迎来到unity学习、unity培训、unity企业培训教育专区,这里有很多U3D资源、U3D培训视频,我们致力于打造业内unity3d培训、学习第一品牌。今天开始做我们的游戏了,组长给分配了任务,我负责做剧情动画,人物血条和种植植物。 一、剧情动画 动画是以多个图片的形式展现的,图片是自己制作的。 private GUITextu_游戏血条动图
文章浏览阅读1k次。*******字符编码ASCII,GB2312,GBK,Unicode,UTF-8比较参考:https://blog.csdn.net/softwarenb/article/details/51994943**环境变量的加载顺序:Mac系统的环境变量,加载顺序为:a. /etc/profileb. /etc/pathsc. ~/.bash_profiled. ~/..._环境变量的顺序
文章浏览阅读316次。▼大型年度AI人物评选——2017中国AI英雄风云榜已于12月4日在乌镇张榜,12月18日在北京国贸三期举行颁奖典礼。榜单评选出年度技术创新人物TOP 10;商业创新人物TOP 10,获取完整榜单请关注网易智能公众号(ID:smartman163),回复关键词“评奖”。本文系网易智能工作室出品聚焦AI,读懂下一个大时代【网易智能讯12月10日消息】不只有你会_人类大脑植入代码
文章浏览阅读3.6k次。几经研究, 终于实现了。time[2020-06-04 11:43:36](?<=\[)(.*)(?=])(pattern) 匹配 pattern 并获取这一匹配。所获取的匹配可以从产生的 Matches 集合得到,在VBScript 中使用 SubMatches 集合,在JScript 中则使用 $0…$9 属性。要匹配圆括号字符,请使用 '\(' 或 '\)'。 (?:pattern) 匹配 pattern 但不获取匹配结..._正则<>里内容