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;
                }
            }
        };

你可能感兴趣的:(list)