2010-12-09 36 views
2

我用FillAfter = true將TranslateAnimation應用於EditText,以保持它在動畫結尾的位置。 動畫可以正常工作,但問題是我無法再輸入edittext。 我認爲這是由於動畫隻影響渲染而不修改實際視圖座標。如何在動畫之後將更改應用於視圖的位置?

有沒有可能保持edittext正常工作的最終座標?

感謝, 丹尼爾

回答

3

Unfotunately動畫只呈現動畫元素的原始像素,而不是它的「Android的實習生」的位置。最好的解決方案(我能夠想出)是使用AnimationListener並在動畫完成後正確設置動畫元素的位置。這裏是我的代碼slideDown searchWrapper:

public void toggleSearchWrapper() { 

    AnimationSet set = new AnimationSet(true); 

    // slideDown Animation 
    Animation animation = new TranslateAnimation(
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, 
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f 
    ); 



    animation.setDuration(300); 
    animation.setFillEnabled(false); 


    animation.setAnimationListener(new AnimationListener() { 

     @Override 
     public void onAnimationStart(final Animation anim) { 
     }; 

     @Override 
     public void onAnimationRepeat(final Animation anim) { 
     }; 

     @Override 
     public void onAnimationEnd(final Animation anim) { 


      // clear animation to prevent flicker 
      searchWrapper.clearAnimation(); 

      // set new "real" position of wrapper 
      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
      lp.addRule(RelativeLayout.BELOW, R.id.branchFinderIncludeHeader); 
      searchWrapper.setLayoutParams(lp); 

     } 

    }); 


    set.addAnimation(animation); 

    // set and start animation 
    searchWrapper.startAnimation(animation); 



} 
相關問題