首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2012-08-15 
List表上增加涂层移动动画效果final LinearLayout animationLayer new LinearLayout(this)??????? anim

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

热点排行