Android UI开发第四十三篇――使用Property Animation实现墨迹天气3.0引导界面及动画实现
来源:程序员人生 发布时间:2014-09-17 19:48:31 阅读次数:4370次
前面写过《墨迹天气3.0引导界面及动画实现》,里面完美实现了动画效果,那一篇文章使用的View
Animation,这一篇文章使用的Property Animation实现。Property Animation是Android3.0以后新增的动画库。
这篇文章的源码以及效果在github。
实现墨迹天气向上滑动的viewpager使用的开源库ViewPager-Android。ViewPager-Android开源库设置app:orientation定义滑动方向。
墨迹天气引导界面共有4个视图,先看一下:(这里引入的图片都是实现后的,截图都是静态图,运行程序看动画效果)。
图一 图二
图三 图四
墨迹天气的引导界面使用的无非是移动、渐变、缩放、转动或者其中几个的组合。我们介绍其中的部分实现。
1、缩放动画
首先是图一的“极低耗电”使用了一个缩放效果,使用Property Animation实现如下:
xml动画文件:
[html]
view plaincopyprint?
- <?xml
version="1.0"
encoding="utf-8"?>
- <set
xmlns:android="http://schemas.android.com/apk/res/android"
- android:ordering="together"
>
-
- <objectAnimator
- android:duration="1000"
- android:interpolator="@android:anim/accelerate_decelerate_interpolator"
- android:propertyName="scaleX"
- android:valueFrom="1.0"
- android:valueTo="1.1"
- android:valueType="floatType"
>
- </objectAnimator>
- <objectAnimator
- android:duration="1000"
- android:interpolator="@android:anim/accelerate_decelerate_interpolator"
- android:propertyName="scaleY"
- android:valueFrom="1.0"
- android:valueTo="1.1"
- android:valueType="floatType"
>
- </objectAnimator>
-
- </set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together" >
<objectAnimator
android:duration="1000"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="scaleX"
android:valueFrom="1.0"
android:valueTo="1.1"
android:valueType="floatType" >
</objectAnimator>
<objectAnimator
android:duration="1000"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="scaleY"
android:valueFrom="1.0"
android:valueTo="1.1"
android:valueType="floatType" >
</objectAnimator>
</set>
java使用:
[java]
view plaincopyprint?
- animation1=(AnimatorSet)AnimatorInflater.loadAnimator(PropertyAnimActivity.this,
- R.animator.tutorail_rotate);
- LinearInterpolator lin = new LinearInterpolator();
- animation1.setInterpolator(lin);
- t1_icon2.setVisibility(View.VISIBLE);
-
- animation1.setTarget(t1_icon2);
- animation1.start();
animation1=(AnimatorSet)AnimatorInflater.loadAnimator(PropertyAnimActivity.this,
R.animator.tutorail_rotate);
LinearInterpolator lin = new LinearInterpolator();
animation1.setInterpolator(lin);
t1_icon2.setVisibility(View.VISIBLE);
animation1.setTarget(t1_icon2);
animation1.start();
2、移动渐变组合动画
图一中下面的箭头使用了移动渐变组合动画,实现如下:
xml文件:
[html]
view plaincopyprint?
- <?xml
version="1.0"
encoding="utf-8"?>
- <set
xmlns:android="http://schemas.android.com/apk/res/android"
- android:ordering="together"
>
-
- <!--
- 可以包含<objectAnimator>,
<valueAnimator>,<set>项
- 属性:android:ordering=["together" | "sequentially"],子集执行顺序
- sequentially Play animations in this set sequentially
- together (default) Play animations in this set at the same time.
- -->
-
- <set
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:ordering="together"
>
- <objectAnimator
- android:duration="1000"
- android:propertyName="translationX"
- android:repeatCount="infinite"
- android:repeatMode="reverse"
- android:valueFrom="0"
- android:valueTo="0"
- android:valueType="floatType"
>
- </objectAnimator>
- <objectAnimator
- android:duration="1000"
- android:propertyName="translationY"
- android:repeatCount="infinite"
- android:repeatMode="reverse"
- android:valueFrom="-15"
- android:valueTo="20"
- android:valueType="floatType"
>
- </objectAnimator>
- </set>
-
- <objectAnimator
- android:duration="1000"
- android:propertyName="alpha"
- android:repeatCount="infinite"
- android:valueFrom="1.0"
- android:valueTo="0.3"
- android:valueType="floatType"
>
- </objectAnimator>
- <!--
- objectAnimator:
-
- android:propertyName
- 对view可以设置一下值:
- translationX and translationY:
- These properties control where the View is located
- as a delta from its left and top coordinates which
- are set by its layout container.
- rotation, rotationX, and rotationY:
- These properties control the rotation
- in 2D (rotation property) and 3D around the pivot point.
- scaleX and scaleY:
- These properties control the 2D scaling of a View around
- its pivot point.
- pivotX and pivotY:
- These properties control the location of the pivot point,
- around which the rotation and scaling transforms occur.
- By default, the pivot point is located at the center of
- the object.
- x and y:
- These are simple utility properties to describe
- the final location of the View in its container,
- as a sum of the left and top values and translationX
- and translationY values.
- alpha:
- Represents the alpha transparency on the View.
- This value is 1 (opaque) by default, with a value of 0
- representing full transparency (not visible).
-
- 还可以设置"backgroundColor"等值
-
- android:valueTo
- float, int, or color. Required. The value where the animated property ends.
- Colors are represented as six digit hexadecimal numbers (for example, #333333).
-
- android:valueFrom
- float, int, or color. The value where the animated property starts. If not specified,
- the animation starts at the value obtained by the property's get method.
- Colors are represented as six digit hexadecimal numbers (for example, #333333).
-
- android:duration
- int. The time in milliseconds of the animation. 300 milliseconds is the default.
-
- android:startOffset
- int. The amount of milliseconds the animation delays after start() is called.
-
- android:repeatCount:重复次数
- 说明:
- infinite:循环执行,
- 具体正整数表示循环次数
-
- android:repeatMode:重复模式,
- 说明:
- restart:重新从头开始执行
- reverse:反方向执行
-
- android:valueType
- Keyword. Do not specify this attribute if the value is a color.
- The animation framework automatically handles color values
-
- intType: Specifies that the animated values are integers
- floatType (default): Specifies that the animated values are floats
- -->
-
- </set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together" >
<!--
可以包含<objectAnimator>, <valueAnimator>,<set>项
属性:android:ordering=["together" | "sequentially"],子集执行顺序
sequentially Play animations in this set sequentially
together (default) Play animations in this set at the same time.
-->
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together" >
<objectAnimator
android:duration="1000"
android:propertyName="translationX"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:valueFrom="0"
android:valueTo="0"
android:valueType="floatType" >
</objectAnimator>
<objectAnimator
android:duration="1000"
android:propertyName="translationY"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:valueFrom="-15"
android:valueTo="20"
android:valueType="floatType" >
</objectAnimator>
</set>
<objectAnimator
android:duration="1000"
android:propertyName="alpha"
android:repeatCount="infinite"
android:valueFrom="1.0"
android:valueTo="0.3"
android:valueType="floatType" >
</objectAnimator>
<!--
objectAnimator:
android:propertyName
对view可以设置一下值:
translationX and translationY:
These properties control where the View is located
as a delta from its left and top coordinates which
are set by its layout container.
rotation, rotationX, and rotationY:
These properties control the rotation
in 2D (rotation property) and 3D around the pivot point.
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
------分隔线----------------------------
------分隔线----------------------------