android - 两个布局动画时的单击监听器行为

标签 android android-layout

我有两个按钮。当按下第一个按钮时,我将我的布局布局转换为顶部,然后从屏幕顶部出现另一个布局。但我的问题是当回到第一个布局时,第二个布局的点击事件仍然在以前的位置被解雇。那么它的解决方案是什么?我在 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);
                    }
                });
            }
        });

最佳答案

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

这是一个例子,

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

如果想在Y方向移动,可以使用translationY。如果要双向移动,需要一个translationX和translationY,同时用一个AnimatorSet来播放。

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

关于android - 两个布局动画时的单击监听器行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17066168/

相关文章:

java - Android 无效使用 SingleClientConnManager : connection still allocated

java - 操作栏按钮位置

android - 将 ArrayList<Object> 存储为 JSON SharedPreference 或 SQLite 数据库表?

android - 在 Android 中以编程方式添加 LinearLayout 不起作用

java - 运行 TextView 失败/Bug(单行选框)

Android 相对布局无法使图像居中

屏幕锁定时 Android 收不到位置更新

java - 无法在 jsseprovider、gmailsender 中附加文件

android webview布局占用剩余空间

android - Android Studio 中的布局验证