flexbox-layout icon indicating copy to clipboard operation
flexbox-layout copied to clipboard

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

Open wealive opened this issue 3 years ago • 6 comments

  • [ ] I have searched existing issues and confirmed this is not a duplicate

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

<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 avatar Jul 01 '21 03:07 wealive

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?

wealive avatar Jul 01 '21 03:07 wealive

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

learner1999 avatar Sep 13 '21 12:09 learner1999

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

dyl169 avatar Jan 07 '22 03:01 dyl169

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

wkp91 avatar Oct 25 '22 08:10 wkp91

Same problem here !

frlgrd avatar Nov 10 '22 10:11 frlgrd

I am having the same problem

pantasystem avatar Feb 02 '23 15:02 pantasystem