0

I was working with the GridView for a while. Everything's working fine on runtime.

However, I have always exactly 5 items on my GridView, and I am looking to make it "more realistic" when rendering it on the "preview" layout.xml : now it "preview" a default number of items depending of its height (let's say for example 24 items).

Every single item can change its height
So, is there any possibility to achieve this by any xml tag, or by overriding the GridView ? Also without proceeding that by the Height would be very clean.

Here is my GridView on my xml layout

<GridView android:id="@+id/my_gridview" android:layout_width="match_parent" android:layout_height="wrap_content" android:numColumns="3"/> 
1
  • Try staggered layout manager with recyclerview Commented Jul 22, 2022 at 16:18

2 Answers 2

1

I didn't find appropriate xml tag for your purpose and I think there isn't a built-in way for it. but I suggest using recyclerview + gridlayoutmanager as @CommonsWare is pointing out. and then you could use tools:itemCount xml attribute to specify your list size.

of course this suggestions are valid only if preview is so important to you.

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, I didn't think about it. I can definitively make it as RecyclerView. Tested the preview and worked. Thank you !
0

Thanks to @mrzbn for the suggested answer. Works totally fine. Combining it with this answer preview of a RecyclerView's contents as Grid
Here is an example of what it worked for me, for whoever had to implement something similar :

<androidx.recyclerview.widget.RecyclerView android:id="@+id/my_grid_recyclerview" android:layout_width="match_parent" android:layout_height="wrap_content" tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager" tools:itemCount="5" tools:orientation="vertical" tools:scrollbars="vertical" tools:spanCount="3" tools:listitem="@layout/my_sample_item"/> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.