I'm trying to set visibility of some elements and I'm using the android:animateLayoutChanges="true" to animate this changes, the animation of the Floating Action Button happens ok, but not works with the menu items, they just blink. Here it is my xml and code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:animateLayoutChanges="true"
android:gravity="center">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="@dimen/standard_elevation"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
<FrameLayout
android:id="@+id/fl_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/my_toolbar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/my_toolbar"
android:id="@+id/rlMainInside"
android:animateLayoutChanges="true">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:clickable="true"
android:src="@drawable/ic_create_black_48dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:src="@drawable/main_center_image"
android:layout_centerInParent="true"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/fl_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/my_toolbar"
android:layout_marginLeft="320dp"/>
</RelativeLayout>
And I use this method to set the visibility of some elements:
private void setMenuVisibility(boolean drawerOpenned) {
Menu menu = myToolbar.getMenu();
for (int i = 0; i < menu.size(); i++){
menu.getItem(i).setVisible(!drawerOpenned);
}
fab.setVisibility(drawerOpenned ? View.INVISIBLE : View.VISIBLE);
}
Can someone help me? I tried to put android:animateLayoutChanges="true" inside the toolbar element, but not happened also.