I got a RecyclerView
inside an HorizontalScrollView
and I want it to use a GridLayoutManager
. This is ok but one thing still bother me, the width of every columns are the same (based on the largest cell width I suppose?). Isn't it possible to wrap width of columns to match the largest cell of this specific column?
It should look to something like this :
Where the orange part is the part taken by the cell's view.
EDIT
We asked me to clarify what I expect. An example is better than words, here you can see a screenshot of a RecyclerView with GridLayoutManager. Each item is a simple TextView containing randomly a text between 10 & 40 characters. The RecyclerView is inside an HorizontalScrollView as said before. We can see that every columns have the same width, despite the fact that no items in this column may fulfill the entire width. What I would like is to remove those useless empty space and having columns with different sizes with each column matching the width of its own largest child.
If you want to test this behavior, you may clone this repo I uploaded on Github : https://github.com/ShargotthDev/TestGrid
As asked, here is my XML layout (very basic) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:id="@+id/gameplay_hotizontalScroll_ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="70dp">
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/recycler_view" />
</HorizontalScrollView>
</RelativeLayout>
EDIT 2
I should have mentioned that some of the cells may have a span size > 1 and the LayoutManager should be vertical so that those cells take more places horizontally and not vertically (don't know if I'm making myself understandable).
Thank's for your time !
You don't need to put your RecyclerView in HorizontalScrollView. See the code below.
Adapter class
row.xml
activity_main.xml
Edit Place your RecyclerView inside NestedScrollView like this
and set your number of spanCount like this
spanCount = 8;