I have a DialogFragment
that contains a RecyclerView
(a list of cards).
Within this RecyclerView
are one or more CardVi
Instead of using any library, easiest solution till the new version comes out is to just open b.android.com/74772. You'll easily find the best solution known to date there.
PS: b.android.com/74772#c50 worked for me
This comment helped me.Put the recyclerview in any other layout (Relative layout is preferable). Then change recyclerview's height/width as match parent to that layout and set the parent layout's height/width as wrap content.
I have not worked on my answer but the way I know it StaggridLayoutManager with no. of grid 1 can solve your problem as StaggridLayout will automatically adjust its height and width on the size of the content. if it works dont forget to check it as a right answer.Cheers..
try deleting : mRecylerView.setHasFixedSize(true);
You must put a FrameLayout as Main view then put inside a RelativeLayout with ScrollView and at least your RecyclerView, it works for me.
The real trick here is the RelativeLayout...
Happy to help.
UPDATE 02.07.2020
This method may prevent recycling and should not be used on large data sets.
UPDATE 05.07.2019
If you are using RecyclerView
inside a ScrollView
, just change ScrollView
to androidx.core.widget.NestedScrollView
. Inside this view there is no need to pack RecyclerView
inside a RelativeLayout
.
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- other views -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- other views -->
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Finally found the solution for this problem.
All you need to do is wrap the RecyclerView
in a RelativeLayout
. Maybe there are other Views which may also work.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>