2011-12-14 79 views
1

我想创建一个视图,隐藏隐藏其他视图,并具有很好的视觉效果。首先,我期待在Android开发者文档,找到animatiion框架,像这样写代码:如何动画处理隐藏视图?

Animation animation = new TranslateAnimation(Animation.ABSOLUTE, 0.0f, 
     Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, -80.0f); 
    animation.setDuration(200); 
    animation.setInterpolator(new AccelerateInterpolator()); 

    searchButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       searchContainer.startAnimation(animation); 
       findViewById(R.id.explore_place_search).setVisibility(View.GONE); 
      } 
     }); 

所以我得到运动,当我按一下按钮,但我想,当动画已经完成了最后的位置冻结视图。用户触摸此元素时更好的方法移动视图(MotionEvent.ACTION_DOWN)。我可以问你怎么做,或者我可以在哪里阅读相关案例?所有的帮助将不胜感激。

回答

2

很多的想法有...动画在android系统相当简单,看看在API demoes:http://developer.android.com/resources/samples/ApiDemos/index.html

这里是二imageviews对海誓山盟顶部淡入淡出的例子:

   Animation fadeIn = new AlphaAnimation(0.00f, 1.00f); 
       fadeIn.setDuration(1000); 
       fadeIn.setAnimationListener(new AnimationListener() { 
        public void onAnimationStart(Animation animation) {} 
        public void onAnimationRepeat(Animation animation) {} 
        public void onAnimationEnd(Animation animation) {} 
       }); 

       Animation fadeOut = new AlphaAnimation(1.00f, 0.00f); 
       fadeOut.setDuration(1000); 
       fadeOut.setAnimationListener(new AnimationListener() { 
        public void onAnimationStart(Animation animation) {} 
        public void onAnimationRepeat(Animation animation) {} 
        public void onAnimationEnd(Animation animation) { 
         placeholderImageView.setVisibility(View.GONE); 
        } 
       }); 
       imageView.setImageBitmap(bitmap); 

       placeholderImageView.startAnimation(fadeOut); 
       imageView.startAnimation(fadeIn); 

这是在代码中完成的,但动画也可以用xml完成​​。