google / flexbox-layout

Flexbox for Android
Apache License 2.0
18.27k stars 1.8k forks source link

Height of RecyclerView with Flexboxlayoutmanager does not work correctly when recyclerview is wrap_content #583

Open wealive opened 3 years ago

wealive commented 3 years ago

Issues and steps to reproduce

I got a NestScrollView with 3 RecyclerView in it.And each recyclerview had a "loadmore"button,when tapped, add 50 new item into it,but the recycler view does not display correct ,only 10or more added,but I expect 50

Expected behavior

Version of the flexbox library

3.0.0

Link to code

<?xml version="1.0" encoding="utf-8"?> <androidx.core.widget.NestedScrollView 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="wrap_content" android:fillViewport="true" android:overScrollMode="never" app:layout_constraintTop_toTopOf="parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="12dp"
    android:layout_marginEnd="12dp"
    android:background="@drawable/bg_white_vp_8"
    android:orientation="vertical"
    android:paddingBottom="12dp">

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:layout_marginTop="20dp"
        android:includeFontPadding="false"
        android:text="常考词汇"
        android:textColor="#0099ff"
        android:textSize="13sp" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_1st"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:nestedScrollingEnabled="false"
        android:paddingEnd="12dp" />

    <RelativeLayout
        android:id="@+id/tv_more_1st"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:background="@drawable/aibk_bg_vocab_select">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:drawableStart="@mipmap/aibk_icon_arrow_down"
            android:drawablePadding="6dp"
            android:gravity="center"
            android:includeFontPadding="false"
            android:text="加载更多"
            android:textColor="#0099ff"
            android:textSize="12sp" />
    </RelativeLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:layout_marginTop="8dp"
        android:includeFontPadding="false"
        android:text="次常考词汇"
        android:textColor="#0099ff"
        android:textSize="13sp" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_2nd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:nestedScrollingEnabled="false" />

    <RelativeLayout
        android:id="@+id/tv_more_2nd"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="#ccebff">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:drawableStart="@mipmap/aibk_icon_arrow_down"
            android:drawablePadding="6dp"
            android:gravity="center"
            android:includeFontPadding="false"
            android:text="加载更多"
            android:textColor="#0099ff"
            android:textSize="12sp" />
    </RelativeLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:layout_marginTop="8dp"
        android:text="不常考词汇"
        android:textColor="#0099ff"
        android:textSize="13sp" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_3rd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:nestedScrollingEnabled="false" />

    <RelativeLayout
        android:id="@+id/tv_more_3rd"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="#ccebff">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:drawableStart="@mipmap/aibk_icon_arrow_down"
            android:drawablePadding="6dp"
            android:gravity="center"
            android:includeFontPadding="false"
            android:text="加载更多"
            android:textColor="#0099ff"
            android:textSize="12sp" />
    </RelativeLayout>
</LinearLayout>

</androidx.core.widget.NestedScrollView>

  rv_1st.layoutManager = FlexboxLayoutManager(
        requireContext(), FlexDirection.ROW,
        FlexWrap.WRAP
    ).apply {
        isAutoMeasureEnabled=true
        alignItems = AlignItems.FLEX_START
    }

    rv_1st.adapter = adapter

adapter.setNewData(it.data.FirstVocabList)

wealive commented 3 years ago

Screenshot_20210701_110919_com lancoo znbkxx InkedScreenshot_20210701_110926_com lancoo znbkxx_LI

only 4 items added,and the other not display,is it recyclerview's height calculate wrong?

learner1999 commented 3 years ago

我也遇到了这个问题,请问后来有解决吗? I also encountered this problem. Was it resolved later?

dyl169 commented 2 years ago

我也遇到了这个问题,请问后来有解决吗?

wkp91 commented 2 years ago

I have the same problem, is there any way to solve it?

frlgrd commented 2 years ago

Same problem here !

pantasystem commented 1 year ago

I am having the same problem