Toolbar overlapping listView

I had a layout with an AppBarLayout and toolbar that overlapped the first item on the ListView below it.  It appears to have been fixed by adding this line

app:layout_behavior="@string/appbar_scrolling_view_behavior"

But the problem was where to add it. The answer was in the layout of the included xml file (second file below).

activity_main.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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="uk.co.jit.daryltest1.MainActivity">

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

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

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

    <include layout="@layout/content_main"
        />

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

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <ListView
        android:id="@+id/lvItems"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dp" />

</LinearLayout>

 

This entry was posted in Android. Bookmark the permalink.

One Response to Toolbar overlapping listView

  1. vidya says:

    it worked thanku

Leave a Reply

Your email address will not be published. Required fields are marked *