安卓XML和java文件中定义基本动画
来源:互联网 发布:网络剧堪比权力的游戏 编辑:程序博客网 时间:2024/06/13 03:25
1.Android 动画的定义
android平台提供了两类动画 第一类是Tween ,即通过对场景里的对象不断做图像变换(平移,缩放,旋转)产生动画效果 第二类是Frame动画,即顺序播放事先做好的图像,跟电影类似
围绕中心旋转的动画
动画效果如下:
做法
(1) xml中定义动画
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate android:duration="5000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:repeatCount="-1" android:toDegrees="-359" /></set>
(2) java代码中定义动画
RotateAnimation ra = new RotateAnimation(0f, -359f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); ra.setDuration(5000); ra.setRepeatCount(-1); //无线循环 ra.setInterpolator(new LinearInterpolator()); //匀速运动 iv.startAnimation(ra);
相关解释:
pivotX 相对于自身x轴的对少 repeatCount 重复的次数 -1表示不停setInterpolator 表示设置旋转速率 LinearInterpolator 匀速 Accelerateinterpolator 加速 Decelerateinterpolator 减速
开始和停止旋转
动画开始if (iv != null && ra != null) { iv.startAnimation(ra); }清除动画if (iv != null && ra != null) { iv.clearAnimation(); }
java代码的一些动画
(1)透明动画(透明—>不透明)
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1); alphaAnimation.setDuration(1000); alphaAnimation.setFillAfter(true);
(2)缩放动画
ScaleAnimation scaleAnimation = new ScaleAnimation( 0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(1000); alphaAnimation.setFillAfter(true);
(3)动画集合Set
AnimationSet animationSet = new AnimationSet(true);
//添加两个动画
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(scaleAnimation);
1 0
- 安卓XML和java文件中定义基本动画
- 安卓开发中如何在XML文件中定义动画
- 安卓xml文件中设置动画匀速旋转无效?
- Android 如何在XML文件中定义动画
- Android 如何在XML文件中定义动画
- 如何定义安卓动画
- 安卓xml文件中<include>用法
- Android XML文件定义4种动画
- 在XML中定义逐帧动画
- 【实训】Android中xml动画定义
- xml文件定义动画(补间动画)--------常用
- web.xml 文件中定义和映射Servlet(1/3)
- web.xml 文件中定义和映射Servlet(2/3)
- web.xml文件中定义和映射Servlet(2/3)
- 动画基础(一) 四种基本动画(xml和java编写)
- android动画详解六 XML中定义动画
- 安卓常用的基本动画代码
- 安卓的基本的动画介绍
- 任务的同步与通信_读书笔记_5
- Linux常用命令
- themecoder
- Glide入门教程——20.动态使用 Model Loaders
- JVM原理和优化
- 安卓XML和java文件中定义基本动画
- 第一天、我的CSDN博客开山篇
- Openvswitch原理与代码分析(2): ovs-vswitchd的启动
- redis 集群
- Openvswitch原理与代码分析(3): openvswitch内核模块的加载
- ViewPager笔记
- how to get UILable text width
- 制作Pascal VOC数据集并在YOLO和Faster RCNN上测试(码字ing)
- Openvswitch原理与代码分析(4):网络包的处理过程