androidandroid-layoutandroid-gridview

Render specific item count on a GridView


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"/>

Solution

  • 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.