1

I have custom toolbar and i want my listview to be below Toolbar . But listview is appearing on the toolbar and my layout_below is not working . I know many question have been asked before . But nothing is working . Please Help me

below is my layoutxml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"

tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView">

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

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/MyListView"
    android:layout_below="@+id/toolbar"
   ></ListView>

</RelativeLayout>

toolbarlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar    
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/orange"
    app:layout_scrollFlags="scroll|enterAlways"
    app:titleTextColor="@color/white"></android.support.v7.widget.Toolbar>

</LinearLayout>
FaisalAhmed
  • 3,469
  • 7
  • 46
  • 76
  • The problem is because your linear layout on toolbarlayout.xml takes all the height of your screen, because you specify it as match parent – HendraWD Jul 30 '16 at 13:31

4 Answers4

2

Question was already answered by other users...

I just would like to add more information.

Your layout can be much simpler. You don't need use RelativeLayout. Just use a LinearLayout with android:orientation="vertical" instead. This way, you will have:

layout.xml

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

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

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/MyListView" />

</LinearLayout>

Toolbar Layout

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_scrollFlags="scroll|enterAlways"
    android:background="@color/orange"
    app:titleTextColor="@color/white" />
guipivoto
  • 18,327
  • 9
  • 60
  • 75
1

Remove the LinearLayout from your toolbarlayout.xml. So your toolbarlayout.xml should look like this:

<android.support.v7.widget.Toolbar    
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/orange"
    app:layout_scrollFlags="scroll|enterAlways"
    app:titleTextColor="@color/white"></android.support.v7.widget.Toolbar>
Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64
0

Use below code it'll work.

my layoutxml

   <?xml version="1.0" encoding="utf-8"?>
    <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="faisal.home.com.tafaqquhfiddin.DuwaListView">

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

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/MyListView"
        android:layout_below="@+id/toolbar"
       ></ListView>

</LinearLayout >
ViramP
  • 1,659
  • 11
  • 11
0

The root layout of toolbarlayout.xml height is "match_parent" change it to "wrap_content". Use the below code it will works.

<?xml version="1.0" encoding="utf-8"?>
<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="faisal.home.com.tafaqquhfiddin.DuwaListView">

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

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/MyListView"
    android:layout_below="@+id/toolbar"/>
</LinearLayout>

toolbarlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar    
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/orange"
    app:layout_scrollFlags="scroll|enterAlways"
    app:titleTextColor="@color/white"/>

</LinearLayout>
Tamilselvan S
  • 91
  • 1
  • 4