Switching visibility. AppBarLayout views have problems locating loaded snippets


I had a strange problem with the new Android design support library ( http://android-developers.blogspot.com.ar/2015/05/android-design-support-library.html ). If I put additional content (for example, LinearLayout) in the AppBarLayout along with the ToolBar and switch the visibility of this content, then the dead space will be displayed at the top of the fragment content to switch fragments.

AppBarLayout does not seem to resize the parent Layout coordinator correctly when the visibility of the content is switched. I have my CoordinatorLayout wrapped in DrawerLayout. I want to switch the visibility of the optional LinearLayout to AppBarLayout depending on which fragment is shown.

Here is my main.xml file for MainActivity:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.CoordinatorLayout android:layout_height="match_parent" android:layout_width="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_vertical""> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="start" android:text="Hello"/> </LinearLayout> </android.support.design.widget.AppBarLayout> <FrameLayout app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.design.widget.CoordinatorLayout> <android.support.design.widget.NavigationView android:id="@+id/navigation" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:menu="@menu/drawer"/> </android.support.v4.widget.DrawerLayout> 
+6
source share
1 answer

I had a similar problem using a support widget. I had a Layout coordinator inside DrawerLayout and an AppBarLayout inside CoordinatorLayout. I had two toolbars inside an AppBarLayout. My goal was to display a toolbar with a ViewPager displaying recyclerview content. I wanted to swap between toolbars when selecting items. In other words, I made one toolbar GONE, and the other was visible and vice versa. Scroll up by clicking on the toolbar at the top of the screen. Everything worked perfectly, except that changing the orientation would show the space for the toolbar, which should disappear. I tried every hack that I could think of to get rid of it, but failed. Then I came across this message and realized that this was a bug in the support library. Then I tried to set FrameLayout to AppBarLayout and then put two toolbars inside FrameLayout and NO MORE SPACE! Now everything works the way I'm going to work. The toolbar is GONE GONE, and only the visible toolbar is displayed even when the orientation is changed.

Hope this helps someone.

+1
source

Source: https://habr.com/ru/post/989826/


All Articles