1

I use CollapsingToolbarLayout in my app in CollapsingToolbarLayout we have a toolbar and a chart that is used MPAndroid chart to draw the x and y point...anyway, the problem is that the toolbar is on the chart and we can't see the top section of the chart(exactly the size of action Bar), how can I put my chart view below the toolbar, the is my code:

<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="300dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="true"
        android:foregroundGravity="bottom|right"
        android:foregroundTintMode="add"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <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/ColorPrimary"
            android:elevation="5dp"
            app:layout_collapseMode="pin"
            app:theme="@style/Toolbar">
        </android.support.v7.widget.Toolbar>

        <com.github.mikephil.charting.charts.LineChart
            android:id="@+id/graph"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar"
            android:background="@color/white"
            app:layout_collapseMode="parallax">
        </com.github.mikephil.charting.charts.LineChart>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

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

farshid83
  • 91
  • 1
  • 12

1 Answers1

2

Reorganise your CollapsingToolbarLayout setting the Toolbar below LineChart

<android.support.design.widget.CoordinatorLayout
    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.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="300dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="true"
            android:foregroundGravity="bottom|right"
            android:foregroundTintMode="add"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <com.github.mikephil.charting.charts.LineChart
                android:id="@+id/graph"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/toolbar"
                android:background="@color/white"
                app:layout_collapseMode="parallax">
            </com.github.mikephil.charting.charts.LineChart>

            <android.support.v7.widget.Toolbar 
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/ColorPrimary"
                android:elevation="5dp"
                app:layout_collapseMode="pin"
                app:theme="@style/Toolbar">
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>
José Carlos
  • 654
  • 6
  • 16