Android CollapsingToolbarLayout title - top edge error

Collapse title ToolbarLayout has a weird top edge, but only when it is collapsed and only when inside a fragment. Prior to version 2.0.0 of the design support library version, everything worked fine.

Video: https://www.youtube.com/watch?v=7WUrFhmvs_Q&feature=youtu.be

XML:

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="256dp" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:scaleType="centerCrop" android:src="@drawable/image_placeholder" app:layout_collapseMode="parallax"/> <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" android:text="Lorem ipsum dolor sit amet enim ..." android:textSize="20sp"/> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout> 

Fragment:

 public class TestFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View view = inflater.inflate(R.layout.test_fragment, container, false); return view; } @Override @CallSuper public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) view.findViewById(R.id.collapsing_toolbar_layout); toolbarLayout.setTitle("Lorem Ipsum"); } } 

Any ideas?

+5
source share
1 answer

I have the same problem right now, but this is because I place it inside FrameLayout and LinearLayout, and they do not call their methods "OnApplyWindowInsets".

Even with the fix, I still get the problem.

But for you, try using only android: fitsSystemWindows = "true" on your CoordinatorLayout, not the rest. I think you see double inserts because you have almost all of your controls.

0
source

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


All Articles