2011-12-14 83 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完成​​。