Scrollview below toolbar in android

user5287166 picture user5287166 · Sep 17, 2015 · Viewed 14.2k times · Source

Is it possible to set scrollbar below a toolbar in Android? I am trying out the scrollbarView I have toolbar attached to my Layout something like this:

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

    <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:background="@color/layoutcolor_background"
        android:orientation="vertical"
        tools:ignore="ContentDescription,RtlHardcoded,NestedWeights">

        <include
            android:id="@+id/toolbar"
            layout="@layout/main_toolbar" />

        <View
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="@drawable/toolbar_dropshadow" />

        <LinearLayout
            android:id="@+id/aandcID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:layout_weight=".50"
            android:baselineAligned="false"
            android:orientation="horizontal">

            <RelativeLayout
                android:id="@+id/alayout"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="1dp"
                android:layout_weight=".50"
                android:background="@color/layoutbackgroudforrow"
                android:gravity="center">

                <ImageView
                    android:id="@+id/aimage"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_centerHorizontal="true"
                    android:paddingBottom="3dp"
                    android:paddingTop="5dp"
                    android:src="@drawable/acc" />

                <TextView
                    android:id="@+id/aType"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/aimage"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:paddingLeft="2dp"
                    android:singleLine="true"
                    android:text="Deposit"
                    android:textColor="@color/blackText"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    tools:ignore="RtlSymmetry,RtlHardcoded,HardcodedText" />

                <TextView
                    android:id="@+id/anumber"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/aType"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:paddingLeft="2dp"
                    android:singleLine="true"
                    android:text="12345678901234567890"
                    android:textColor="@color/blackText"
                    android:textSize="18sp"
                    tools:ignore="RtlSymmetry,RtlHardcoded,HardcodedText" />

                <ImageView
                    android:id="@+id/rupeeIcon"
                    android:layout_width="12dp"
                    android:layout_height="14dp"
                    android:layout_below="@+id/anumber"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="8dp"
                    android:layout_toLeftOf="@+id/accatext"
                    android:background="@drawable/rupees_symbol"
                    android:paddingBottom="2dp"
                    android:visibility="visible"
                    tools:ignore="ContentDescription" />

                <TextView
                    android:id="@+id/accatext"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/anumber"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:paddingLeft="2dp"
                    android:singleLine="true"
                    android:text="09876543210987654321"
                    android:textColor="@color/numbertext"
                    android:textSize="16sp"
                    tools:ignore="RtlSymmetry,RtlHardcoded,HardcodedText" />
            </RelativeLayout>
        </LinearLayout>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/footer_band" />

    </LinearLayout>
</ScrollView>

With the above code.. Toolbar is also scrolled and hence it get cut too. Is there a way freeze toolbar and then scroll other views.

It would be great if somebody could guide me?

Thanks!

Answer

Jin picture Jin · Sep 17, 2015

Just do something like this

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

           <!-- Rest of your content -->

        </LinearLayout>

    </ScrollView>

</LinearLayout>