Created
August 20, 2019 10:05
-
-
Save abhishekgargx/72d29bb4996809b2e097037c88392493 to your computer and use it in GitHub Desktop.
How to use Recycle view with wrap content as height.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > ### **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