I am following this tutorial http://www.exoguru.com/android/ui/recyclerview/custom-android-grids-using-recyclerview.html and I've minimized the the total number of element to 4. I want to view the recyclerView at middle of the screen.but When I use "wrap_content" as it's height, the recyclerView is showing at the top of the screen.But if I specifies the height of it (for example: "350dp") it is showing at the center of the screen as i wanted.What went wrong when is use "wrap_content"
Asked
Active
Viewed 967 times
0
-
If you are only showing 4 items at once, why are you using a `RecyclerView`? The chances of those items ever being recycled is near 0. – Bryan Herbst Nov 10 '15 at 20:06
2 Answers
0
RecyclerView's concept is supposed to displaying a lot of items, which overflows out of the screen. And recycling (re-using) a minimal set of Views to show a bunch of items.
About your case, there are too few items to fill up the screen. So this is not weird.

hata
- 11,633
- 6
- 46
- 69
0
"Wrap_content" does not work properly with RecyclerViews (as stated here), but there are some solutions to this problem on this site.
If all you want to do is center the RecyclerView vertically, you could do something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Space
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"/>
<Space
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>

Community
- 1
- 1

Valentin Winkler
- 33
- 1
- 8