如何在动画后将更改应用于视图的位置?

时间:2010-12-09 10:55:44

标签: android animation coordinates android-edittext

我使用FillAfter = true将TranslateAnimation应用于EditText,以便将其位置保持在动画的末尾。 动画工作正常,但问题是我不能再进入edittext了。 我认为这是因为动画只影响渲染而不修改实际的视图坐标。

是否有可能保持编辑文本的最终坐标正常工作?

谢谢, 丹尼尔

1 个答案:

答案 0 :(得分:3)

不幸的是,动画只渲染动画元素的原始像素,而不是它的“android-intern”位置。最好的解决方案(我能想到的)是使用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);



}
相关问题