1

I nerd to create sticky headers in my android application. So I followed a tutorial to create them and in it the user has added to lines in his xml file.

This are the lines:

android:layout_behavir="@string/appbar_scrolling_view_behavior"
android:layout_scrollFlags="scroll|exitUntilcolapsed">

But when I try to add the two lines to my code the autocomplete don't recognize them and if I add them anyway the application gives an error.

I have read around and what I found was to include the android.support.design library. I have don that but my problem persist.

Can someone give mi a full example of how to put this to work?

This is my XML file:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.example.manuelrodrigues.myapplication.ScrollingActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize" />

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/AppTheme.AppBarOverlay">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|exitUntilcolapsed"
                android:layout_behavir="@string/appbar_scrolling_view_behavior"
                android:layout_scrollFlags="scroll|exitUntilcolapsed">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="56dp"
                    android:background="#ff0000"
                    android:text="Teste" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="56dp"
                    android:background="#00ff00"
                    android:text="Teste3" />

            </LinearLayout>

        </android.support.design.widget.AppBarLayout>

        <include layout="@layout/content_scrolling" />
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

And this are my imported libs: And this are my imported libs:

Manuel_Rodrigues
  • 560
  • 2
  • 18

3 Answers3

2

You should use app:layout_scrollFlags instead of android:layout_scrollFlags .

  1. Wrong tag name android:layout_behavir

Don't

android:layout_scrollFlags="scroll|exitUntilcolapsed"
android:layout_behavir="@string/appbar_scrolling_view_behavior"

Do

app:layout_scrollFlags="scroll|exitUntilcolapsed"
android:layout_behaviour ="@string/appbar_scrolling_view_behavior"

You should include below in Parent Layout Section .

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"

Finally Clean-Rebuild-Run .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

change this..

android:layout_behavir="@string/appbar_scrolling_view_behavior"
android:layout_scrollFlags="scroll|exitUntilcolapsed">

to

app:layout_scrollFlags="scroll|exitUntilcolapsed"
android:layout_behaviour ="@string/appbar_scrolling_view_behavior"
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

Try this, its exitUntilCollapsed and not exitUntilcolapsed.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.example.manuelrodrigues.myapplication.ScrollingActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize" />

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:layout_behavir="@string/appbar_scrolling_view_behavior"
                android:layout_scrollFlags="scroll|exitUntilCollapsed">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="56dp"
                    android:background="#ff0000"
                    android:text="Teste" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="56dp"
                    android:background="#00ff00"
                    android:text="Teste3" />

            </LinearLayout>

        </android.support.design.widget.AppBarLayout>

    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>
JRG
  • 4,037
  • 3
  • 23
  • 34