Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace NestedScrollView in older API<21?

I have a problem with a layout fragment:

<android.support.v4.widget.NestedScrollView 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:layout_gravity="fill_vertical"
    android:clipToPadding="false"
    android:fillViewport="true"
    android:nestedScrollingEnabled="true" <!-- this don't work with api levels older than 21 -->
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:id="@+id/elements" />
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

I need disappear/appear toolbar when the user scroll the fragment. This method don't work with API 19(for example): What would you do with this Android device?

like image 212
Helpme Avatar asked Dec 10 '22 14:12

Helpme


2 Answers

This doesn't work in XML under API 21, but the corresponding code works as it's in the support library:

recyclerView.setNestedScrollingEnabled(true);
like image 87
Herrbert74 Avatar answered Jan 12 '23 16:01

Herrbert74


You need to use a CoordinatorLayout. Take a look to this guide from CodePath

https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

like image 45
Daniel Luque Avatar answered Jan 12 '23 15:01

Daniel Luque