cachapa / ExpandableLayout

An expandable layout container for Android
Apache License 2.0
2.34k stars 273 forks source link

ExpandableLayout blocks recyclerview #72

Closed Narinc closed 5 years ago

Narinc commented 5 years ago

When both expandablelayout and recyclerview are on the same screen, recyclerview can't init. After collapse/expand the layout, Updating ui when expandablelayout is expanded.

`<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools">

<data>

    <import type="android.view.View.OnClickListener" />

    <import type="android.view.View" />

    <variable
        name="listener"
        type="com.otelz.mobile.ui.activity.facilityDetail.fragment.room.list.RoomListScreenListener" />

    <variable
        name="viewModel"
        type="com.otelz.mobile.ui.activity.facilityDetail.fragment.room.list.RoomListViewModel" />
</data>

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/divider"
    android:clickable="true"
    android:focusable="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/divider"
        android:fitsSystemWindows="true"
        android:theme="@style/Widget.AppCompat.Light.ActionBar"
        app:contentPaddingTop="0dp"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp"
            app:elevation="0dp"
            app:layout_scrollFlags="scroll|snap">

            <android.support.design.card.MaterialCardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:background="@color/white">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:context="com.otelz.mobile.ui.activity.facilityDetail.fragment.room.list.RoomListActivity">

                    <android.support.design.card.MaterialCardView
                        android:id="@+id/cardFilter"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">

                            <TextView
                                android:id="@+id/tvFilter"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/nunito_bold"
                                android:includeFontPadding="false"
                                android:onClick="@{() -> listener.toggleFilterView()}"
                                android:padding="8dp"
                                android:text="@string/filter"
                                android:textColor="@color/black" />

                            <ImageButton
                                android:id="@+id/ivFilter"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentEnd="true"
                                android:layout_centerVertical="true"
                                android:layout_marginEnd="8dp"
                                android:background="?attr/selectableItemBackgroundBorderless"
                                android:contentDescription="@string/image_description"
                                android:onClick="@{() -> listener.toggleFilterView()}"
                                android:scaleType="centerCrop"
                                android:tint="@color/black"
                                app:srcCompat="@drawable/ic_arrow_down_black_24dp" />
                        </RelativeLayout>
                    </android.support.design.card.MaterialCardView>

                    <net.cachapa.expandablelayout.ExpandableLayout
                        android:id="@+id/expandableRoomFilter"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/cardFilter"
                        android:paddingStart="8dp"
                        android:paddingEnd="8dp"
                        android:paddingBottom="8dp"
                        app:el_duration="500"
                        app:el_expanded="true"
                        app:el_parallax="0.5"
                        tools:el_expanded="true">

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

                            <android.support.v7.widget.RecyclerView
                                android:id="@+id/recyclerPensionFilter"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp"
                                app:layoutManager="android.support.v7.widget.GridLayoutManager"
                                app:spanCount="2" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp"
                                android:fontFamily="@font/nunito_bold"
                                android:includeFontPadding="false"
                                android:text="@string/person_count_in_room"
                                android:textColor="@color/black"
                                android:textSize="@dimen/font_small" />

                            <android.support.v7.widget.RecyclerView
                                android:id="@+id/recyclerPersonFilter"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="4dp"
                                app:layoutManager="android.support.v7.widget.GridLayoutManager"
                                app:spanCount="6" />
                        </LinearLayout>

                    </net.cachapa.expandablelayout.ExpandableLayout>
                </RelativeLayout>

            </android.support.design.card.MaterialCardView>

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerRoomList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:roomList="@{viewModel.filteredRooms}" />
</android.support.design.widget.CoordinatorLayout>

`

cachapa commented 5 years ago

Setting wrap_content on the RecyclerView is generally a bad idea because it can't compute it's size until its items are instantiated. When ExpandableLayout is collapsed its children are set to visibility=gone for performance purposes, which causes the RV to not layout its own items.

Setting a fixed height on the RV should fix the issue.

Narinc commented 5 years ago

Thanks. You're right!!