【问题标题】:Click Listener behavior when two layouts get animated单击两个布局动画时的侦听器行为
【发布时间】:2014-07-23 13:28:10
【问题描述】:

我有两个按钮。当第一个按钮被按下时,我正在将我的布局布局转换为顶部,然后从屏幕顶部开始另一个布局。但我的问题是当回到第一个布局时,第二个布局的点击事件仍然在以前的职位上被解雇。那么它的解决方案是什么?我在 SO 和 Google 上找到了很多,但仍然无法找到正确的解决方案。所以请有人帮我解决这个问题。在此先感谢.

TranslateAnimation tr1 = new TranslateAnimation(0, 0, 0, -1100);
        tr1.setDuration(1000);
        tr1.setFillAfter(true);
        layout_login.startAnimation(tr1);
        tr1.setAnimationListener(new AnimationListener() {

            public void onAnimationStart(Animation animation) {

            }

            public void onAnimationRepeat(Animation animation) {

            }

            public void onAnimationEnd(Animation animation) {
                layout_signup.setVisibility(View.VISIBLE);
                TranslateAnimation tr2 = new TranslateAnimation(0, 0,
                        -1100, 0);
                tr2.setDuration(1000);
                tr2.setFillAfter(true);
                tr2.setInterpolator(MainActivity.this,
                        android.R.anim.linear_interpolator);
                layout_signup.startAnimation(tr2);

                tr2.setAnimationListener(new AnimationListener() {

                    public void onAnimationStart(Animation animation) {

                    }

                    public void onAnimationRepeat(Animation animation) {

                    }

                    public void onAnimationEnd(Animation animation) {
                        home_activity_btn_login.setEnabled(true);
                    }
                });
            }
        });

【问题讨论】:

  • 意思是你扩展 1 个布局并折叠其他布局?
  • 你想在展开和折叠动画的帮助下做到这一点吗?
  • @Pratik :好吧,只想做一个布局正在上升。布局触及手机屏幕顶部后,我想显示来自手机屏幕顶部的另一种布局。我已经完成了它在翻译动画的帮助下,但我的问题是在翻译后我能够点击第二个布局的事件仍然在其先前的位置被触发。它的解决方案是什么?
  • 我想看看你的 XML,你能发一下吗?
  • @Pratik:我已经完成了不使用 XML 的 java 代码。

标签: android android-layout


【解决方案1】:

我认为这是旧动画师方案的一个错误(我相信一个众所周知的错误,涉及有时不工作后的填充)。尝试改用 ObjectAnimator

这是一个例子,

ObjectAnimator oa = ObjectAnimator.ofFloat(view, "translationX", 0, 100f);
oa.setDuration(1000);
oa.start();

如果要沿 Y 方向移动,可以使用 translateY。如果要双向移动,则需要translationX和translationY,并使用AnimatorSet同时播放。

看看这个comment to this question. 使用旧的动画API,显然尽管fillAfter(true),按钮的点击位置保持不变。这证实了您的问题。所以只要使用新的 API,你的状态应该很好。

【讨论】:

  • 我认为这将有助于我在 X 坐标中移动我的布局,但是如果我想将我的布局移动到 Y 坐标中,那么我应该怎么做?我认为我不会帮助我。我说的对吗?
  • ObjectAnimator oa = ObjectAnimator.ofFloat(view, "translationY", 0, 5f);会做的
  • 查看我对问题的编辑。我发现了另一个具有完全相同问题的问题。我的解决方案应该可以解决,仅供参考
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多