I have a RecyclerView
with StaggeredGridLayoutManager
inside a ScrollView
. As you can't set WRAP_CONTENT
parameter for RecylerView
(doesn't support it), I have to calculate the height of view, dynamically. (Adapter gets populated dynamically. Its an infinite scroll view). You can find similar behavior in Pinterest app. (Pictured below). I also wrote my layout view hierarchy.
<ScrollView>
<LinearLayout>
<some_layouts>
.
.
</some_layouts>
<RecyclerView>
</RecyclerView>
<LinearLayout>
<ScrollView>
How can I get same thing in my app? I dug through the classes api but found nothing. Can anyone help me on this?
Although answer is too late and i was also finding the solution i came across the library in which size of the item layout is dynamically adjusted with few lines of code.
Just add
dependencies {
implementation 'com.google.android:flexbox:0.3.2'
}
Github Library Link
Use below code:-
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getContext());
layoutManager.setFlexWrap(FlexWrap.WRAP);
recyclerView.setLayoutManager(layoutManager);
So you don't have calculate height dynamically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With