Search code examples
androidandroid-toolbarandroid-coordinatorlayout

Progressbar below Toolbar in CoordinatorLayout


I have a layout XMl like this :

<CoordinatorLayout>
    <AppBarLayout>
        <CollapsingToolbarLayout>
            <RelativeLayout/>
            <Toolbar/>
        </CollapsingToolbarLayout>
    </AppBarLayout>
    <RecyclerView/>
</CoordinatorLayout>

I want to add a horizontal progressbar just below the toolbar and above the recycler view to indicate data loading for recycler view items.

With a relative layout, I could have simply provided a android:layout_below property for progressbar below action bar. But being new to Coordinator Layout and Toolbar, I am unable to get the results.


Solution

  • If you want to hide ProgressBar with Toolbar wrap Toolbar inside LinearLayout and put ProgressBar as a first child of this LinearLayout. Assign

    orientation="vertical"
    

    If you would like ProgressBar to be always visible, then wrap RecyclerView inside LinearLayout and put ProgressBar as a first child. Set the orientation. Remember to add

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    

    as a paramter of LinearLayout (It must pass the scrolling to the child)