Skip to content

Instantly share code, notes, and snippets.

@abhishekgargx
Created August 20, 2019 10:05
Show Gist options
  • Select an option

  • Save abhishekgargx/72d29bb4996809b2e097037c88392493 to your computer and use it in GitHub Desktop.

Select an option

Save abhishekgargx/72d29bb4996809b2e097037c88392493 to your computer and use it in GitHub Desktop.
How to use Recycle view with wrap content as height.
> ### **there are two ways i found working well for me. To make recycle view height behave as wrap content **
### **First way**
> Putting recycler view inside in the Nested Scroll view to acheive wrap content functionality
```
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:text="Sample"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</NestedScrollView>
```
### **Second Way**
> Putting recycler view inside in the relative layout works well, to achieve same wrap content effect.
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</LinearLayout>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment