Android Api demo系列(一) (App>Activity>Animation)

App>Activity>Animation

这里主要介绍补间动画应用到Activity之间的切换,这是4.0新出的动画效果

动画xml都编写在res/anim文件夹中,例如:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="0.0" android:toAlpha="1.0"
       android:duration="@android:integer/config_longAnimTime" />
这是一个渐变动画效果。

<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/decelerate_interpolator">
    <scale android:fromXScale="2.0" android:toXScale="1.0"
           android:fromYScale="2.0" android:toYScale="1.0"
           android:pivotX="50%p" android:pivotY="50%p"
           android:duration="@android:integer/config_mediumAnimTime" />
</set>
这是缩放动画效果。
第一种:运行动画代码:
startActivity(new Intent(Animation.this, AlertDialogSamples.class));
overridePendingTransition(R.anim.fade, R.anim.hold);//参数一,进入动画;参数二,退出动画
这种运行代码在4.0以前也可以使用,但是下面的必须在4.0以后了。
第二种:
ActivityOptions opts = ActivityOptions.makeCustomAnimation(Animation.this, R.anim.fade, R.anim.hold);
startActivity(new Intent(Animation.this, AlertDialogSamples.class), opts.toBundle());
这两种代码运行的效果有点不同,太微小,自己可以去查看api demo的动画效果。

第三种:
在你点击view的位置打开acitivity,放大效果
private OnClickListener mScaleUpListener = new OnClickListener() {
        public void onClick(View v) {
            // Create a scale-up animation that originates at the button
            // being pressed.
            ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(
                    v, 0, 0, v.getWidth(), v.getHeight());
            // Request the activity be started, using the custom animation options.
            startActivity(new Intent(Animation.this, AlertDialogSamples.class), opts.toBundle());
        }
    };
第四种:
说句实话这种完全搞不懂想要干嘛,运行和第三种也差不多
 private OnClickListener mZoomThumbnailListener = new OnClickListener() {
        public void onClick(View v) {

            v.setDrawingCacheEnabled(true);
            v.setPressed(false);
            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);
        }
    };

总结:第一,第二种需要创建补间动画的xml文件实现
第三种,第四种不用创建,关联的属性和你点击的view有关。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值