I need to create a Horizontal RecyclerView with dynamic rows and columns, and every cell has the same width, but different height. Which means column width should be consistent and row height is dynamic.
I've tried implementing this behavior with FlexBoxLayoutManager, StaggeredGridLayoutManager, GridLayoutManager. Also attempted with GridView but then realized it's not supported with horizontal scroll.
I'm trying to find something that is similar to UICollectionView in iOS.
As seen in the photo, columns are unlimited, and number of cells per column depends on the height of the cells. So each column has a different number of cells.
FlexBoxLayoutManager supports what you're trying to achieve.
You want to use it within a RecyclerView have a look at FlexDirection
https://github.com/google/flexbox-layout#flexboxlayoutmanager-within-recyclerview
Related
I have a recyclerview with GridLayoutManager as layout managar and what I want to achieve is like image below
As you can see every row may have multiple item just based on item width and each item is a TextView with wrap_content width but all item have same height.
I know it is possible to set row span by SpanSizeLookup but for doing that, I should know the count of spans before while my list rows will fill just by items width
Can anyone help me?
You might be better off with a different Layout manager like FlexboxLayoutManager https://github.com/google/flexbox-layout
It has lots of flexibility of on controlling when the wrap the row (automatic or manual) and you can specify lots of controls on how individual cells can grow/shrink to fill a line.
There are lots of examples on the github page.
But as a starting point you could manually wrap before cells 3 and 7 to give you the 3 on the first row and 4 on the second.
Or setting FlexWrap will do it automatically based on size
I am implementing recycler listview with 2 columns using StaggeredGridLayoutManager.
And I am getting grids with all different heights.
But I want grids populating with only two specific height dimensions.
Kindly help me to resolve this issue.
I am trying to move my app from using GridView to using RecyclerView with GridLayoutManager. I am new to RecylcerViews, but have successfully converted my ListViews, now working on my GridView. A couple things I am unsure about:
My current GridView has a certain number of columns, determined at runtime, with each grid column the same, hard-coded width. It is scrollable both horizontally and vertically (I wrap my Gridview in a HorizontalScrollView). So I basically need to have a view with a set number of columns that are a set width, irrespective of screen width.
I have been having problems finding a method to set the column(span) width for GridLayoutManager, so I assume that is not how GridLayoutManager. It almost sounds like it is built to always fit all columns on the screen, rather than letting them spill off the screen? What is the best way to tell GridLayoutManager that I want, for example, 6 columns that are each 150 units wide (either dp or pixels)?
For scrolling in both directions, it sounds like I can use my current approach and just wrap my RecyclerView in a HorizontalScrollView, is that correct?
Make the width of the RecyclerView wrap_content and set the number of spans you want. (Make sure parents of the RecyclerView are also wrap_content.) When you create the item views in the RecyclerView's onCreateViewHolder() make sure that it is the width that you want. The RecyclerView will grow to the width of the view holder layout times the number of spans.
All you need to do now is to wrap everything in a HorizontalScrollView.
I want to achieve something similar to the attached image
I was thinking of using TableLayout with 2 columns for each row.
There will be padding in order to be apart of each other. Then I will put white background for the cell. Lastly, I'll just add the ImageView and TextView.
The images and text are dynamically generated. I will get the image URL and display them.
So, are there any better or more efficient way for implementing what I want to achieve? TableLayout doesn't seem to be that efficient.
Your diagram looks pretty much like a grid - for which you can use a GridLayout in Android: https://developer.android.com/reference/android/widget/GridLayout.html
A layout that places its children in a rectangular grid.
The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is taken into account).
Every one of the items in the grid can be a Cardview (https://developer.android.com/training/material/lists-cards.html) - and that way you will also benefit of a consistent look and feel with Android, without much effort.
Take into account that the cards (every item in the grid) will have the same height, tho: How to make a grid layout of CardViews with variable height?.
If the height of the elements will be variable, you should better take a look to the StaggeredGridLayoutManager: https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html
What you have to do is use a RecyclerView with a GridLayoutManager.
For a full working implementation: https://inducesmile.com/android/android-gridlayoutmanager-with-recyclerview-in-material-design/
I'm unsure as to what the differences between the two of them are and which I should use for my purpouses?
What I'm trying to do is create a custom virtual numpad with text inputs and that can dynamically change its contents to have a date picker.
So I need a layout system which supports many different sized cells inside it.
Which better suits my needs and what's the difference?
In my experience I had both GridLayout and TableLayout give me the same results. They both seem to stretch the columns to fit the widest child element. Neither will give you gird lines or borders around the cells.
From the official docs on GridLayout:
Row and Column Specs
Children occupy one or more contiguous cells, as defined by their rowSpec and columnSpec layout parameters. Each spec defines the set of rows or columns that are to be occupied; and how children should be aligned within the resulting group of cells. Although cells do not normally overlap in a GridLayout, GridLayout does not prevent children being defined to occupy the same cell or group of cells. In this case however, there is no guarantee that children will not themselves overlap after the layout operation completes.
and from the TableLayout:
The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML.
So it seems to me that the GridLayout is a bit more versatile and probably what you are looking for.