my project has only one toolbar that surrounded by AppBarLayout and also a NestedScrollView control below it that has a CardView layout surrouned linearlayout. no the problem is that the nested scroll overlap the toolbar like this i show in image
and also in run time it pass the app like there is no toolbar like this:
this is my code:
<?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/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="7dp"
app:theme="@style/ThemeOverlay.AppCompat"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:titleTextColor="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
></android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp"
>
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
scroll_view_item code is here:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
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="wrap_content"
android:layout_margin="16dp"
android:elevation="5dp"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dummy Header"
android:textColor="@android:color/holo_red_light"
android:textSize="20sp"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/app_text"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
just surround your code with linearlayout like this:
<?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/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="7dp"
app:theme="@style/ThemeOverlay.AppCompat"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:titleTextColor="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
></android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp"
>
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
<include layout="@layout/scroll_view_item" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
You forgot the to specify the behavior on the ScrollView.
Add this line to your NestedScrollView :
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Add below line to your NestedScrollView
:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With