Android GridLayoutManager with both column and row span - android

I'm using GridLayoutManager(GLM) in my RecyclerView. In the RecyclerView, I will populate the CardViews, how can I set my GLM to render only one CardView in the whole screen ?
If I set the span size as 1, it renders one CardView per row, not whole screen.
In Simple, I want to show 1 CardView occupying two columns and two rows. How to achieve this ?

Just double the height of the card for it to take the space of 2 rows. The height of each row is dependent on the single item you inflate (in your case a cardView).

Related

How to add dynamic number of sub items to android recyclerview item

I have a requirement in which there will be multiple child items to a RecycylerView Item. As per the requirement a single recycler view item can have maximum of four horizontal Childs and 2 vertical Childs at max. I have used recyclerview inside a recyclerview to achieve this by the results are not per the requirement. In short I need something like this
The results of recyclerview inside recyclerview is something like this. The items are not stretching to full length as highlighted in yellow.
How can I achieve this? I have user grid layout manager on inner recyclerview with spancount of 3 and tried with 4 as well. Converted to linearlayout manger horizontal but not able to get the desired result.
You can use GridLayoutManager for this. Just call the setSpanSizeLookup method and determine how many columns an item should take.

Android Step type GridLayout

I'm trying to achieve a design for recycler view in grid layout style. Any Input towards achieving it is very helpful.
I have to design for span size 2 only.
Design :
I tried to use GridLayoutManager with span size 2
If you mean that list should scroll horizontally and each next column should be following of previous one. I think you can done it by horizontal recycler view with items that contain two views and top space margin which increases sequentially.
Height of the RecyclerView should be calculated and set by last column in code.

Set the the height of all items on a row of a GridView depending on the tallest item

In an app that I'm developing I need to display a GridView with items that depending on its text (more than one line of text) may be of different height and I want to avoid that the items are shown with different heights since it's quite ugly.
When the text is only one line the GridView the items in the row are displayed properly but when the text is larger than one line they are shown like this:
How I can avoid this behavior and set the highest height of an item of a row as the height of all items of that row?

Center items in listview vertically

I have a listview, the listviews width and height should be set to match parent. So, if the listview is fully stretched and has only 2 items in it, they are at the top of the listview and on the bottom is too much useless space. I want to know, if it is possible to center these 2 items in this listview vertically, if yes, how?
List height depends on the height of the list item, that is populating the list.
If you have only two items in the list why don't you simply use a Linear Layout instead with weightSum?
Anyway, if you want to achieve the result you requested in your question you have to get the display height using method
getResources().getDisplayMetrics().heightPixels in activity context.
After that you need to set the height of the list item to the height you retrieved earlier divided by 2.
And also set gravity to center_vertical for the textviews in the list.

How to change the divider height of listview dynamically?

I have a listview in which there should be different divider height
between different rows. So, how can we set the divider height
dynamically?
Suppose, I have 10 rows and there should be a divider height of 5
between first 2 rows and then there should be a divider height of 1
between next 5 rows and so on.
Can someone let me know the way of doing this?
One way would be to make the dividers rows. Set them as not enabled in your isEnabled adapter method. I do that for section headers, but it is almost the same thing. Another way would be to manually lay out your whole list by implementing onLayout. If the dividers can be empty space, it might work to set top or bottom margins for the root view of your rows. In xml that would be:
android:layout_marginTop='5px'
Otherwise, just make the dividers part of the rows.

Categories

Resources