Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AppBarLayout and CollapsingToolbarLayout without a toolbar

There's not many examples of these new layouts out on the Internet and those few that are out there are all based on same basic approach. How about if I don't have a proper toolbar in my app, but still want to use the cool functionalities of new material design layouts?

One thing that I've been trying out is using a MapView and RecyclerView inside CoordinatorLayout with a parallax scrolling effect. It works great, but there's a problem. If my adapter count is low, the RecyclerView doesn't remain on the bottom of screen. Here's some images to better describe the problem.

Initial screen:

enter image description here

RecyclerView scrolls over MapView, leaving blank space below: enter image description here

Is there a way to keep RecyclerView on bottom?

My xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways">

        <com.google.android.gms.maps.MapView
            android:id="@+id/tts_main_map"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            app:layout_collapseMode="parallax" />
    </android.support.design.widget.CollapsingToolbarLayout>

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />

</android.support.design.widget.CoordinatorLayout>
like image 381
Tomislav Turcic Avatar asked Oct 31 '22 18:10

Tomislav Turcic


1 Answers

Try to set the android:minHeight property of the CollapsingToolbarLayout dynamically depending on how many items you have in the list. I.e. you should set (pseudo-code):

  minHeight = allAvailableHeight - (oneListItemHeigh * listItemCount)

PS. It just an idea, I did not tried. But I think it should works.

like image 118
MobileX Avatar answered Nov 15 '22 04:11

MobileX