淡入后的动画设置按钮不可点击



我只是想在应用程序中淡入我的图像按钮。然而,问题是,图像按钮逐渐消失,但之后无法点击。这意味着onclickevents在显示时单击它们时不会启动。是因为我将按钮的原始位置设置为layout_marginleft:-100dp;即使我把边距设置为-100dp,有没有办法让它发挥作用?你能告诉我为什么吗?

这是我的功能:

    public void onclickMenu(View view) {
    final int menuOffsetTime = 4000;
    final ImageButton menuClose = (ImageButton) findViewById(R.id.menu_close);
    final ImageButton menuOpen = (ImageButton) findViewById(R.id.menu_open);
    final ImageButton expButton = (ImageButton) findViewById(R.id.export);
    final ImageButton opButton = (ImageButton) findViewById(R.id.open);
    final ImageButton setButton = (ImageButton) findViewById(R.id.settings);
    final AnimationSet animationSetIn = new AnimationSet(false);
    final AnimationSet animationSetOut = new AnimationSet(false);
    Animation animationIn = AnimationUtils.loadAnimation(this, R.anim.menu_anim_in);
    Animation animationOut = AnimationUtils.loadAnimation(this, R.anim.menu_anim_out);
    expButton.clearAnimation();
    opButton.clearAnimation();
    setButton.clearAnimation();
    if(animationIn != null && animationOut != null) {
        animationSetIn.addAnimation(animationIn);
        animationSetOut.addAnimation(animationOut);
        animationSetIn.setInterpolator(new AccelerateDecelerateInterpolator());
        animationSetOut.setInterpolator(new AccelerateDecelerateInterpolator());
        if(view.getId() == R.id.menu_open) {
            animationSetIn.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {}
                @Override
                public void onAnimationRepeat(Animation animation) {}
                @Override
                public void onAnimationEnd(Animation animation) {
                    animationSetOut.setStartOffset(menuOffsetTime);
                    animationSetOut.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {}
                        @Override
                        public void onAnimationRepeat(Animation animation) {}
                        @Override
                        public void onAnimationEnd(Animation animation) {}
                    });
                    if(menuOpen.getVisibility() == View.INVISIBLE) {
                        opButton.startAnimation(animationSetOut);
                        setButton.startAnimation(animationSetOut);
                        if(export) {
                            expButton.startAnimation(animationSetOut);
                        }
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                menuClose.setVisibility(View.INVISIBLE);
                                menuOpen.setVisibility(View.VISIBLE);
                            }
                        }, menuOffsetTime);
                    }
                }
            });
            opButton.startAnimation(animationSetIn);
            setButton.startAnimation(animationSetIn);
            opButton.setEnabled(true);
            if(export) {
                expButton.startAnimation(animationSetIn);
            }
            menuClose.setVisibility(View.VISIBLE);
            menuOpen.setVisibility(View.INVISIBLE);
        } else {
            opButton.startAnimation(animationSetOut);
            setButton.startAnimation(animationSetOut);
            if(export) {
                expButton.startAnimation(animationSetOut);
            }
            menuClose.setVisibility(View.INVISIBLE);
            menuOpen.setVisibility(View.VISIBLE);
        }
    }
}

我在菜单中有这个_anim_in:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <translate android:fromXDelta="0%" android:toXDelta="100%"
        android:duration="2000" android:fillAfter="true" />
</set>

这个在我的菜单中_anim_out:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="false">
    <translate android:fromXDelta="100%" android:toXDelta="0%"
        android:duration="2000" android:fillAfter="true" />
</set>

这在我的布局文件中:

<ImageButton
    android:layout_width="@dimen/menu_button_width"
    android:layout_height="@dimen/menu_button_height"
    android:id="@+id/export"
    android:onClick="onclickExport"
    android:layout_gravity="left|center_vertical"
    android:layout_marginTop="0dp"
    android:layout_marginLeft="-100dp"
    android:background="@drawable/export" />
<ImageButton
    android:layout_width="@dimen/menu_button_width"
    android:layout_height="@dimen/menu_button_height"
    android:id="@+id/open"
    android:onClick="onclickOpen"
    android:layout_gravity="left|center_vertical"
    android:layout_marginTop="70dp"
    android:layout_marginLeft="-100dp"
    android:background="@drawable/open" />
<ImageButton
    android:layout_width="@dimen/menu_button_width"
    android:layout_height="@dimen/menu_button_height"
    android:id="@+id/settings"
    android:onClick="onclickSettings"
    android:layout_gravity="left|center_vertical"
    android:layout_marginTop="140dp"
    android:layout_marginLeft="-100dp"
    android:background="@drawable/settings" />

提前谢谢!

根据xml,

onclickMenu方法未使用。

您的图像按钮都没有调用onclickmenu方法。那个么,你们认为这个方法会被称为它自己吗?

如果仍然有问题,请将此添加到图像按钮。

android:clickleable="true"

希望它能帮助

相关内容

  • 没有找到相关文章

最新更新