Android 渐变动画(Tween animation)
来源:互联网 发布:如何做网络直播 编辑:程序博客网 时间:2024/05/22 00:43
Android 渐变动画(Tween animation)
Android中的渐变动画是通过定义在XML文件中的参数实现的。
今天给大家展示一个例子,例子比较全面,参数可以随意修改。
anim XML
在res目录下的anim目录创建xml文件,记得必须是anim目录。
我创建了两个文件分别为animator.xml和animator2.xml。使用XML文件的好处就是阅读和复用都比较好。
animator.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="1.4" android:fromYScale="1.0" android:toYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="1400" /> <set android:interpolator="@android:anim/decelerate_interpolator"> <scale android:fromXScale="1.4" android:toXScale="0.0" android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="800" android:fillBefore="false" /> <rotate android:fromDegrees="0" android:toDegrees="-45" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="800" /> </set></set>
animator2.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <alpha android:duration="1400" android:fromAlpha="0.0" android:toAlpha="1.0" /> <scale android:duration="1400" android:fromXScale="1.0" android:toXScale="1.0" android:fromYScale="1.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" /> <translate android:duration="1400" android:fromXDelta="5%" android:toXDelta="0.0" android:fromYDelta="5%" android:toYDelta="0.0" /> <rotate android:duration="1400" android:fromDegrees="0" android:toDegrees="100" android:pivotX="50%" android:pivotY="50%" /></set>
和控件结合
有了anim的动画参数,要和那个控件进行结合呢?我使用了两个ImageView,
首先是layout文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:gravity="center_horizontal" android:orientation="vertical" android:layout_height="match_parent"> <ImageView android:id="@+id/spaceshipImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ic_header_stub" /> <ImageView android:id="@+id/spaceshipImage2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ic_header_stub" /></LinearLayout>
使用Animation类来控制layout中的两个图片的动作。
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage); Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.animator); spaceshipImage.startAnimation(hyperspaceJumpAnimation); ImageView spaceshipImage2 = (ImageView) findViewById(R.id.spaceshipImage2); Animation hyperspaceJumpAnimation2 = AnimationUtils.loadAnimation(this, R.anim.animator2); spaceshipImage2.startAnimation(hyperspaceJumpAnimation2);
这段代码就不上传github了,直接可以摘下来使用。
0 0
- Android 渐变动画(Tween animation)
- 史上最简单android动画之Tween Animation(渐变动画)
- android开发(9) 渐变动画演示(Tween Animation)
- android 动画 补间动画,渐变动画 Tween Animation
- Android动画 之 Tween Animation(AlphaAnimation 透明度渐变)
- Android动画 之 Tween Animation(ScaleAnimation 大小渐变)
- Android动画 之 Tween Animation(TranslateAnimation 位置渐变)
- android-animation Tween动画
- Android Tween Animation 动画(二)
- Android Tween Animation 动画(一)
- 浅谈Android变换动画(Tween Animation)
- android补间动画(Tween Animation)
- Android 动画(一)-View Animation(Tween Animation)
- 【UX】Android动画 - Tween Animation
- Android动画之Tween Animation
- Android动画介绍-Tween Animation
- Android动画之Tween Animation
- Android动画之Tween Animation
- iOS8之后,新的注册通知方式,解决注册通知失败问题
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(九)
- pch文件用到的地方详解
- SSE技术简介
- 如何培养孩子的金钱价值观
- Android 渐变动画(Tween animation)
- 1108. Finding Average
- node.js url
- pdb — The Python Debugger
- 实用的 Python —— os.system() 在 python 语句中执行 dos 命令
- 转行入软件开发的开篇贴(日记里程碑文章)
- GitHub NB的开源汇总,一个一个学吧
- 各数据交换格式性能对比(协议兼容性、序列化反序列化耗时、流量、可读性)
- 接口(C# 编程指南)