`
jzhua2006
  • 浏览: 300708 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

List表上增加涂层移动动画效果

阅读更多

final LinearLayout animationLayer = new LinearLayout(this);
       

animationLayer.setGravity(Gravity.CENTER);

        Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();

        final ImageView imageView = new ImageView(this);

        final TranslateAnimation translateAnimation = new TranslateAnimation(
                0f, width / 5, 0.0f, (height / 2 - height / 16));
        translateAnimation.setDuration(ANIMATION_DURATION);

        final ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.2f,
                1.0f, 0.2f, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.0f);
        scaleAnimation.setDuration(ANIMATION_DURATION);

        addContentView(animationLayer, new LayoutParams(width, height));

        AnimationListener animationListener = new AnimationListener()
        {

            @Override
            public void onAnimationStart(Animation animation)
            {
            }

            @Override
            public void onAnimationRepeat(Animation animation)
            {

            }

            @Override
            public void onAnimationEnd(Animation animation)
            {
                mAnimHandler.sendEmptyMessage(CLEAR_ANIMATIONLAYER);
            }

        };

        translateAnimation.setAnimationListener(animationListener);

        mAnimHandler = new Handler()
        {
            @Override
            public void handleMessage(Message message)
            {

                // icon of download item to show
                // Bitmap icon = (Bitmap) message.obj;

                switch (message.what)
                {

                    case INIT_ANIMATION_RES:
                        animationLayer.setVisibility(View.VISIBLE);
                        animationLayer.removeAllViews();

                        imageView.setImageResource(R.drawable.icon);

                        // icon
                        animationLayer.addView(imageView);

                        sendEmptyMessage(START_ANIMATION);

                        break;
                    case START_ANIMATION:

                        canClickBtn = false;
                        animationLayer.startAnimation(translateAnimation);

                        if (animationLayer.getChildCount() > 0)
                        {
                            animationLayer.getChildAt(TOP_LAYER)
                                    .startAnimation(scaleAnimation);
                        }
                        else
                        {
                            throw new IndexOutOfBoundsException();
                        }

                        break;
                    case CLEAR_ANIMATIONLAYER:

                        canClickBtn = true;
                        // clear all views in this layer
                        animationLayer.setVisibility(View.INVISIBLE);
                        animationLayer.clearAnimation();
                        animationLayer.removeAllViews();

                        // call back of UI,go to next step
                        if (null != mListener)
                        {
                            mListener.onLoad();
                        }
                        else
                        {
                            throw new NullPointerException();
                        }
                        break;

                    default:
                        break;
                }
            }
        };

分享到:
评论
1 楼 青春的、脚步 2012-05-27  

相关推荐

Global site tag (gtag.js) - Google Analytics