Android:下载动画,图标飞入下载管理动画实现

有空再讲解!

动画实现如下:  


public static Button sActionBarDownload;  //title栏的下载
    public static FrameLayout sParentView;  //获取父view
    protected ImageView mImageSwitcher;
    // 下载飞出动画的视图
    public ImageView mAnimationImageView = null;
    
    //获取屏幕的整个大view
    sParentView = (FrameLayout) findViewById(R.id.parent_view);
    mActionBarContainer = (ActionBarContainer) findViewById(R.id.actionbar);
    sActionBarDownload = (Button) findViewById(R.id.btn_download_recommend);

    private void iconFlyOutAnimation(final AppInfoDataBean app, final View v) {
        int[] location = new int[2];
        mImageSwitcher.getLocationInWindow(location);  //要下载应用图标的位置,相对于window的位置
        int width = mImageSwitcher.getWidth();
        int height = mImageSwitcher.getHeight();


        if (MyActivity.sParentView != null)  //title下载的位置
        {
            //获取到目标view相对于window的位置
            int[] locationRelative = new int[2];
            MyActivity.sActionBarDownload.getLocationInWindow(locationRelative);

            //将源view放到ImageView中
            mAnimationImageView = new ImageView(getContext());
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, height);
            params.leftMargin = locationRelative[0] - location[0];
            params.topMargin = location[1] - locationRelative[1];

            //获取到源图片的当前view,并设置到Drawable
            ImageView iconImage = (ImageView) mImageSwitcher.getCurrentView();
            mAnimationImageView.setImageDrawable(iconImage.getDrawable());
            //将动画添加到控件内,源加到目标中
            MyActivity.sParentView.addView(mAnimationImageView, params);

            //获取目标的位置控件的长、宽
            int[] locationDst = new int[2];
            locationDst[0] = MyActivity.sActionBarDownload.getWidth();
            locationDst[1] = MyActivity.sActionBarDownload.getHeight();

            int destXp = locationDst[0] / 2;
            int destYp = locationDst[1] / 2;
            int destX = params.leftMargin - destXp;
            int destY = params.topMargin - destYp + DrawUtils.dip2px(20);
            //位移
            Animation translateAnimation = new TranslateAnimation(-destX, DrawUtils.dip2px(12), 0, -destY);
            translateAnimation.setDuration(600);
            //缩放
            Animation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleAnimation.setDuration(600);
            //旋转动画效果  
            Animation rotateAnimation = new RotateAnimation(0f, 720, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            rotateAnimation.setDuration(600);

            AnimationSet animationSet = new AnimationSet(true);
            animationSet.setInterpolator(new DecelerateInterpolator(2.0f));

            animationSet.addAnimation(rotateAnimation);
            animationSet.addAnimation(scaleAnimation);
            animationSet.addAnimation(translateAnimation);
            //            BaseDataActivity.mActionBarDownload.InterceptTouchEvent(true); //设置不可点击

            animationSet.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    if (mAnimationImageView != null && mAnimationImageView.getTag() == animation) {
                        MyActivity.sParentView.removeView(mAnimationImageView);

                        mAnimationImageView = null;
                        // 运行完动画再下载
                        downLoad(app);
                    }
                    //                    BaseDataActivity.mActionBarDownload.onInterceptTouchEvent(false);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }

                @Override
                public void onAnimationStart(Animation animation) {

                }
            });

            mAnimationImageView.startAnimation(animationSet);
            mAnimationImageView.setTag(animationSet);
        }
    } 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值