淡入后动画集按钮不可点击

时间:2014-04-23 09:22:52

标签: android user-interface mobile

我只想在我的应用程序中淡入我的图像按钮。然而,问题是图像按钮正在淡入但之后不可点击。这意味着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);
        }
    }
}

我在menu_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>

这在我的menu_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" />

提前谢谢!

1 个答案:

答案 0 :(得分:2)

根据您的xml,

onclickMenu方法未被使用。

您的图像按钮都没有调用onclickmenu方法。所以你认为方法被称为自己?

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

机器人:可点击=&#34;真&#34;

希望它会有所帮助