【问题标题】:How can I apply the changes to the position of a view after an animation?如何在动画后将更改应用到视图的位置?
【发布时间】:2011-10-28 20:42:39
【问题描述】:

我将 TranslateAnimation 应用于具有 FillAfter=true 的 EditText,以保持其在动画结束时的位置。 动画工作正常,但问题是我不能再进入编辑文本了。 我认为这是因为动画只影响渲染而不修改实际视图坐标。

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

谢谢, 丹尼尔

【问题讨论】:

    标签: android animation coordinates android-edittext


    【解决方案1】:

    不幸的是,动画只渲染动画元素的原始像素,而不是它的“android-intern”位置。最好的解决方案(我能想出的)是使用 AnimationListener 并在动画完成后正确设置动画元素的位置。这是我将 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);
    
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-10
      • 1970-01-01
      相关资源
      最近更新 更多