0

I have an activity containing a Toolbar and a Fragment containing a GridView. Here is the layout of the 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>

My Fragment is inserted in the content_frame layout.

Here is the layout of my 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>

Pretty standard stuff.

I'm animating the ToolBar when scrolling the GridView in order to make it disappear/appear from the top.

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);

The animation resources are the default ActionBar animation for Android.

Everything is working perfectly, except that when the ToolBar is not visible, I don't receive the click events on my GridView where the ToolBar was originally positioned. I also tried to make the Toolbar GONE but it didn't help.

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) {

        }
    });

Does anyone had the same issue ? Do you know why and how to solve this ?

Thank you

Solution :

The solution is to use ObjectAnimator :

ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mToolbar, "translationY", 0);
objectAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
objectAnimator.start();
Andros
  • 4,069
  • 1
  • 22
  • 30

1 Answers1

0

You can find the answer here, but it due to limitations with the old animation system :)

Community
  • 1
  • 1
rogeliog
  • 3,632
  • 4
  • 27
  • 26
  • Well, it say that the animation doesn't actually change the bounds of the view, I get that. However I put the Toolbar visibility to GONE, so the my Fragment under should receive the event right ? – Andros Apr 30 '15 at 21:55
  • Ok, I just tried with ObjectAnimator and it's working. Don't really know why though. – Andros Apr 30 '15 at 22:08