What I would like to achieve
My application has a Toolbar that contains 2 AutoCompleteTextView . I would like to show the second only when the user selected someting in the first and hides it again if the first is cleared (I have an “X” in AutoCompleteTextView to clear it).
I would like the Toolbar animate between these two states, expanding and fading in the second AutoCompleteTextView when something is selected in the first, and the second AutoCompleteTextView fades out and collapses the Toolbar > when the first is cleared.
What I tried but didn't work
I tried using LayoutTransition , both in the android:animateLayoutChanges XML settings, and in the code, declaring LayoutTransition and setting it to a LinearLayout containing both my AutoCompleteTextView s.
The first time I tried this as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" style="@style/CategoryStyle.Vertical" tools:context=".MainActivity"> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toolbar_main" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" style="@style/ToolbarStyle"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/linear_toolbar"> <com.mwd.shoppinglist.Utility.AutoCompleteTextViewNoFilter android:id="@+id/shop_chooser" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Autocomplete" android:hint="@string/chooseShop" android:textSize="16sp" android:drawableRight="@drawable/ic_action_cancel"/> <com.mwd.shoppinglist.Utility.AutoCompleteTextViewNoFilter android:id="@+id/item_chooser" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Autocomplete" android:hint="@string/autoCompleteHint" android:textSize="16sp" android:drawableRight="@drawable/ic_action_cancel_dark"/> </LinearLayout> </android.support.v7.widget.Toolbar> <android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"/> <TextView android:id="@+id/main_temp1" android:text="@string/pick_a_market" style="@style/TempTextView"/> <Button android:id="@+id/main_btn_start" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/btn_start" android:textSize="16sp" android:visibility="gone"/> </LinearLayout>
Toolbar contains a LinearLayout to which I set the LayoutTransition in code. This handler looked pretty good: the Toolbar expands, and the second AutoCompleteTextView disappears.
The problem was disappearing : the Toolbar instantly resets, while I still see the second AutoCompleteTextView on the white background of my RecyclerView , and after a while the AutoCompleteTextView disappears and the Toolbar expands quickly and quickly.
The second time I tried this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" style="@style/CategoryStyle.Vertical" tools:context=".MainActivity" android:id="@+id/linear_toolbar"> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toolbar_main" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" style="@style/ToolbarStyle"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <com.mwd.shoppinglist.Utility.AutoCompleteTextViewNoFilter android:id="@+id/shop_chooser" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Autocomplete" android:hint="@string/chooseShop" android:textSize="16sp" android:drawableRight="@drawable/ic_action_cancel"/> <com.mwd.shoppinglist.Utility.AutoCompleteTextViewNoFilter android:id="@+id/item_chooser" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Autocomplete" android:hint="@string/autoCompleteHint" android:textSize="16sp" android:drawableRight="@drawable/ic_action_cancel_dark"/> </LinearLayout> </android.support.v7.widget.Toolbar> <android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"/> <TextView android:id="@+id/main_temp1" android:text="@string/pick_a_market" style="@style/TempTextView"/> <Button android:id="@+id/main_btn_start" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/btn_start" android:textSize="16sp" android:visibility="gone"/> </LinearLayout>
This time the extinction was handled well: AutoCompleteTextView disappears and then the Toolbar is compressed.
This time there was a problem: AutoCompleteTextView disappears on a white background of my RecyclerView and after a while the Toolbar expands.
Both times, the appearance / disappearance of the second AutoCompleteTextView handled by setting the Visibility code to VISIBLE or GONE .
I also tried using two Toolbar with AutoCompleteTextView , each of which gliding to / from the second, but I really think that in some situations it looks ugly.