当Toolbar GONE时,OnClickListener不会触发

时间:2015-04-30 21:47:19

标签: android toolbar android-toolbar

我的活动包含ToolbarFragment,其中包含GridView。 以下是Activity

的布局
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.v7.widget.Toolbar
        android:id="@+id/home_toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/abc_action_bar_default_height_material_custo"
        android:background="@color/black">

        <include layout="@layout/custom_action_bar"/>

    </android.support.v7.widget.Toolbar>

</FrameLayout>

我的Fragment已插入content_frame布局。

以下是我Fragment的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

        <GridView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/gridView"
            android:paddingTop="@dimen/abc_action_bar_default_height_material_custo"
            android:clipToPadding="false"/> 

</RelativeLayout>

非常标准的东西。

滚动ToolBar时,我正在为GridView制作动画,以使其从顶部消失/显示。

mShowAB = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.abc_slide_in_top);
mHideAB = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.abc_slide_out_top);
mShowAB.setFillAfter(true);
mHideAB.setFillAfter(true);

动画资源是Android的默认ActionBar动画。

除了ToolBar不可见,我没有收到GridView最初定位的ToolBar上的点击事件时,一切都运行正常。 我也试图让Toolbar GONE但它没有帮助。

mHideAB.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (mToolbar != null) {
                mToolbar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

有没有人有同样的问题?你知道为什么以及如何解决这个问题吗?

谢谢

解决方案:

解决方案是使用ObjectAnimator:

ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mToolbar, "translationY", 0);
objectAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
objectAnimator.start();

1 个答案:

答案 0 :(得分:0)

您可以找到答案here,但由于旧动画系统的限制而导致:)

相关问题