ApiDemos示例学习(2)——App->Activity->Animation

现在介绍一下com.example.android.app包下的Animation示例。

关键类及函数:

ActivityOption

overridePendingTransition()

makeCustomAnimation()makeThumbnailScaleUpAnimation

该示例定义了六种动画:

(1)       Fade in,新出现的Activity由浅入深逐渐出现;

(2)       Zoom in,新出现的Activity由大到小逐渐出现;

(3)       Modern fade in,新出现的Activity由浅入深逐渐出现(系统版本大于JELLY_BEAN);

(4)       Modern zoom in,新出现的Activity由大到小逐渐出现(系统版本大于JELLY_BEAN);

(5)       Scale up,新出现的Activity由小到大逐渐出现(系统版本大于JELLY_BEAN);

(6)       Thumbnail zoom,先出现的Activity在点击的地方有小到大出现(系统版本大于JELLY_BEAN);

以上(2)—(6)要求版本在JELLY_BEAN以上;

Android中Animation分为以下两种:

(1)       Frame Animation,帧动画,由一组图像顺序显示显示动画;

(2)       Tween Animation,渐变动画动画,对单个可以附加动画的对象进行各种变化来实现动画;

在android-16对应的ApiDemos示例中,其中:

(1)-(2)附加动画方式:

       overridePendingTransition(int enterAnim, int exitAnim)

              参数

       enterAnim:对应于进入Activity的动画资源Id;

       exitAnim:对应于离开Activity的动画资源Id;

(3)-(5)附加动画方式:

       makeCustomAnimation(Context context, int enterResId, int exitResId)

              说明

              Create an ActivityOptions specifying a custom animation to run when the activity is displayed.

              参数

       enterAnim:对应于进入Activity的动画资源Id;

       exitAnim:对应于离开Activity的动画资源Id;

(6)附加动画方式:

v.setDrawingCacheEnabled(true);//开启缓存,如果其后调用了getDrawable(),将在

//Bitmap中绘制View

v.setPressed(false);                                      //确保在动画开启之前未被Pressed

v.refreshDrawableState();

Bitmap bm = v.getDrawingCache();

Canvas c = new Canvas(bm);

c.drawARGB(255, 255, 0, 0);

ActivityOptions opts = ActivityOptions.makeThumbnailScaleUpAnimation(v, bm, 0, 0);

// Request the activity be started, using the custom animation options.

startActivity(new Intent(Animation.this, AlertDialogSamples.class), opts.toBundle());

v.setDrawingCacheEnabled(false);

         makeThumbnailScaleUpAnimation(View source, Bitmap thumbnail, int startX, int startY),该函数的详细说明参见官方文档

 

<set> 为其它animation类型<alpha>,<scale>,<translate>和<rotate>或其它<set>的容器。

android:interpolator 为Interpolator资源ID,Interpolator定义了动画的变化速率,动画的各帧的显示可以加速,减速,重复显示。

android:shareInterpolator 如果想为<set>中的各个子动画定义共享interpolator,shareInterpolator 则设为true.

<alpha> 定义Fade in ,Fade out 动画,其对应的Android类AlphaAnimation,参数由fromAlpha,toAlpha定义。

<scale>定义缩放动画,其对应的Android类为ScaleAnimation,参数由fromXScale,toXScale,fromYScale,toYScale,pivotX,pivotY定义,pivotX,pivotY定义了缩放时的中心。

<translate>定义平移动画,其对应的Android类为TranslateAnimation,参数由fromXDelta,toXDelta,fromYDelta,toYDelta定义。

<rotate>定义选择动画,其对应的Android类RotateAnimation,参数由fromDegrees,toDegrees,pivotX,pivotY, pivotX,pivotY定义选择中心。

 

 

动画文件的定义比较简单,就不赘述了!

(PS:该示例运行的效果图会尽快补上)

 

Ok,差不多了!

原文地址:https://www.cnblogs.com/rainmonth/p/3599536.html