我如何申请动画后更改视图的位置? [英] How can I apply the changes to the position of a view after an animation?

查看:112
本文介绍了我如何申请动画后更改视图的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我applyed一个TranslateAnimation与FillAfter = TRUE一个EditText,以保持其位置在动画的结尾。
动画工作正常,但问题是,我不能进入到的EditText了。
我认为这是由于这种动画只会影响呈现,而无需修改实际的视图坐标。

I applyed a TranslateAnimation to an EditText with the FillAfter=true in order to keep its position at the end of the animation. The animation works properly but the problem is that I can't enter to the edittext anymore. I think it's due to the fact that the animation affects only the rendering without modifying the actual view coordinates.

是否有可能保持与EditText上正常工作最终的坐标?

Is there any possibility to maintain the final coordinates with the edittext normally working?

谢谢,
丹尼尔

Thanks, Daniele

推荐答案

Unfotunately动画只呈现动画元素的原始像素,而不是它的Android的实习生的位置。最好的解决方案(我能拿出)是使用AnimationListener并正确设置动画元素的位置动画完成后。这里是我的code到了slideDown一个searchWrapper:

Unfotunately the animation only renders the raw pixels of the animated element, but not its "android-intern" position. The best solution (that i am able to come up with) is to use an AnimationListener and set the position of the animated element correctly after the animation has finished. Here is my code to slideDown a 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);



}

这篇关于我如何申请动画后更改视图的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆