Android UI开发第四十三篇——使用Property Animation实现墨迹天气3.0引导界面及动画实现

前面写过墨迹天气3.0引导界面及动画实现,里面完美实现了动画效果,那一篇文章使用的View Animation,这一篇文章使用的Property Animation实现。Property Animation是Android3.0以后新增的动画库。

这篇文章的源代码以及效果在github

    实现墨迹天气向上滑动的viewpager使用的开源库ViewPager-Android。ViewPager-Android开源库设置app:orientation定义滑动方向。


    墨迹天气引导界面共同拥有4个视图。先看一下:(这里引入的图片都是实现后的,截图都是静态图,执行程序看动画效果)。

               

图一                                                                                          图二

   

               

图三                                                                                        图四



    墨迹天气的引导界面使用的无非是移动、渐变、缩放、转动或者当中几个的组合。我们介绍当中的部分实现。


1、缩放动画


    首先是图一的“极低耗电”使用了一个缩放效果。使用Property Animation实现例如以下:

    xml动画文件:

   

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <set xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:ordering="together" > 
  4.  
  5.     <objectAnimator 
  6.         android:duration="1000" 
  7.         android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
  8.         android:propertyName="scaleX" 
  9.         android:valueFrom="1.0" 
  10.         android:valueTo="1.1" 
  11.         android:valueType="floatType" > 
  12.     </objectAnimator> 
  13.     <objectAnimator 
  14.         android:duration="1000" 
  15.         android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
  16.         android:propertyName="scaleY" 
  17.         android:valueFrom="1.0" 
  18.         android:valueTo="1.1" 
  19.         android:valueType="floatType" > 
  20.     </objectAnimator> 
  21.  
  22. </set> 

java使用:

  1. animation1=(AnimatorSet)AnimatorInflater.loadAnimator(PropertyAnimActivity.this,   
  2.                 R.animator.tutorail_rotate);  
  3.         LinearInterpolator lin = new LinearInterpolator(); 
  4.         animation1.setInterpolator(lin); 
  5.         t1_icon2.setVisibility(View.VISIBLE); 
  6.          
  7.         animation1.setTarget(t1_icon2);   
  8.         animation1.start();  


2、移动渐变组合动画


    图一中以下的箭头使用了移动渐变组合动画,实现例如以下:

    xml文件:

  1. <?

    xml version="1.0" encoding="utf-8"?> 

  2. <set xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:ordering="together" > 
  4.  
  5.     <!-- 
  6.     能够包括<objectAnimator>, <valueAnimator>,<set>项 
  7.     属性:android:ordering=["together" | "sequentially"],子集运行顺序 
  8.     sequentially    Play animations in this set sequentially 
  9.     together (default)  Play animations in this set at the same time. 
  10.     --> 
  11.  
  12.     <set 
  13.         xmlns:android="http://schemas.android.com/apk/res/android" 
  14.         android:ordering="together" > 
  15.         <objectAnimator 
  16.             android:duration="1000" 
  17.             android:propertyName="translationX" 
  18.             android:repeatCount="infinite" 
  19.             android:repeatMode="reverse" 
  20.             android:valueFrom="0" 
  21.             android:valueTo="0" 
  22.             android:valueType="floatType" > 
  23.         </objectAnimator> 
  24.         <objectAnimator 
  25.             android:duration="1000" 
  26.             android:propertyName="translationY" 
  27.             android:repeatCount="infinite" 
  28.             android:repeatMode="reverse" 
  29.             android:valueFrom="-15" 
  30.             android:valueTo="20" 
  31.             android:valueType="floatType" > 
  32.         </objectAnimator> 
  33.     </set> 
  34.  
  35.     <objectAnimator 
  36.         android:duration="1000" 
  37.         android:propertyName="alpha" 
  38.         android:repeatCount="infinite" 
  39.         android:valueFrom="1.0" 
  40.         android:valueTo="0.3" 
  41.         android:valueType="floatType" > 
  42.     </objectAnimator> 
  43.     <!-- 
  44.    objectAnimator: 
  45.      
  46.         android:propertyName 
  47.             对view能够设置一下值: 
  48.                translationX and translationY:  
  49.                    These properties control where the View is located  
  50.                    as a delta from its left and top coordinates which  
  51.                    are set by its layout container. 
  52.                rotation, rotationX, and rotationY:  
  53.                    These properties control the rotation  
  54.                    in 2D (rotation property) and 3D around the pivot point. 
  55.                scaleX and scaleY:  
  56.                    These properties control the 2D scaling of a View around  
  57.                    its pivot point. 
  58.                pivotX and pivotY:  
  59.                    These properties control the location of the pivot point,  
  60.                    around which the rotation and scaling transforms occur.  
  61.                    By default, the pivot point is located at the center of  
  62.                    the object. 
  63.                x and y:  
  64.                    These are simple utility properties to describe  
  65.                    the final location of the View in its container,  
  66.                    as a sum of the left and top values and translationX  
  67.                    and translationY values. 
  68.                alpha:  
  69.                    Represents the alpha transparency on the View.  
  70.                    This value is 1 (opaque) by default, with a value of 0  
  71.                    representing full transparency (not visible). 
  72.                     
  73.                还能够设置"backgroundColor"等值 
  74.                     
  75.         android:valueTo 
  76.             float, int, or color. Required. The value where the animated property ends.  
  77.             Colors are represented as six digit hexadecimal numbers (for example, #333333). 
  78.          
  79.         android:valueFrom 
  80.             float, int, or color. The value where the animated property starts. If not specified,  
  81.             the animation starts at the value obtained by the property's get method.  
  82.             Colors are represented as six digit hexadecimal numbers (for example, #333333). 
  83.          
  84.         android:duration 
  85.             int. The time in milliseconds of the animation. 300 milliseconds is the default. 
  86.          
  87.         android:startOffset 
  88.             int. The amount of milliseconds the animation delays after start() is called.   
  89.          
  90.         android:repeatCount:反复次数 
  91.             说明: 
  92.             infinite:循环运行。 
  93.             详细正整数表示循环次数 
  94.              
  95.         android:repeatMode:反复模式, 
  96.             说明: 
  97.                 restart:又一次从头開始运行 
  98.                 reverse:反方向运行 
  99.                  
  100.         android:valueType 
  101.            Keyword. Do not specify this attribute if the value is a color.  
  102.            The animation framework automatically handles color values 
  103.             
  104.            intType: Specifies that the animated values are integers 
  105.            floatType (default): Specifies that the animated values are floats 
  106.     --> 
  107.  
  108. </set> 

posted on 2017-05-01 17:04  wgwyanfs  阅读(226)  评论(0编辑  收藏  举报

导航