2018-04-23 04:04:12 8 Comments
I have cards with different width and I would like to create a Grid Layout where width = match the parent (filling the screen) and fixed height. I would like to set the cards in the Grid layout so the number of columns changes accordingly to the width of the elements that can fit the row.
So the elements will be set in a horizontal row till they can fit the screen and then go to the next row, with a vertical scroll when they exceed the fixed height.
I am trying to use a Grid Layout but I don't know if it the suitable solution for this. I use native Android.
Here a picture of it should look like:
Thanks.
Related Questions
Sponsored Content
30 Answered Questions
[SOLVED] How to get the build/version number of your Android application?
- 2011-01-06 14:43:35
- Fahad Ali Shaikh
- 554795 View
- 1202 Score
- 30 Answer
- Tags: android android-emulator android-manifest
18 Answered Questions
[SOLVED] How do I align views at the bottom of the screen?
- 2010-03-05 13:04:23
- gav
- 511501 View
- 627 Score
- 18 Answer
- Tags: android xml user-interface android-layout
12 Answered Questions
[SOLVED] RecyclerView GridLayoutManager: how to auto-detect span count?
- 2014-10-31 01:22:49
- foo64
- 79255 View
- 101 Score
- 12 Answer
- Tags: android android-recyclerview android-gridlayout gridlayoutmanager
8 Answered Questions
[SOLVED] HorizontalScrollView within ScrollView Touch Handling
- 2010-04-15 14:12:08
- Joel
- 127112 View
- 224 Score
- 8 Answer
- Tags: android ontouchlistener android-scrollview horizontalscrollview
18 Answered Questions
[SOLVED] Linear Layout and weight in Android
- 2010-04-23 13:18:23
- Janusz
- 374324 View
- 252 Score
- 18 Answer
- Tags: android android-linearlayout android-layout-weight
15 Answered Questions
[SOLVED] Nested Recycler view height doesn't wrap its content
- 2014-10-30 09:34:29
- Twibit
- 96273 View
- 173 Score
- 15 Answer
- Tags: android android-layout android-studio android-recyclerview android-support-library
2 Answered Questions
[SOLVED] Adding equally sized views dynamically in GridLayout
- 2018-05-11 02:58:01
- BadCode
- 778 View
- 1 Score
- 2 Answer
- Tags: android android-gridlayout
6 Answered Questions
[SOLVED] GridLayout Column width
- 2013-09-02 15:48:49
- bwoogie
- 74570 View
- 44 Score
- 6 Answer
- Tags: android android-layout android-gridlayout
1 Answered Questions
[SOLVED] How to put a view in exact column and row and make it fill that column GridLayout android
- 2017-02-12 21:16:36
- vibetribe93
- 336 View
- 1 Score
- 1 Answer
- Tags: java android android-custom-view android-gridlayout
0 Answered Questions
How to get row and column position/number of a view in GridLayout?
- 2013-09-21 15:34:51
- r4jiv007
- 1156 View
- 0 Score
- 0 Answer
- Tags: android android-layout textview android-gridlayout
2 comments
@dev 2018-04-23 04:21:14
You can use Staggered GridView libraries. For eg. https://github.com/etsy/AndroidStaggeredGrid Edit: add dependency in build.gradle and in your xml you can add:
@Antonio Mele 2018-04-23 07:32:18
Thank you. I've tried your solution and it was good but not exactly what I need. The reply of @Nilesh Rathod suit my need. Thank you for your help, by the way it's an interesting solution.
@Nilesh Rathod 2018-04-23 04:26:18
You can use
FlexboxLayoutManager
Add the following dependency to your build.gradle file:
SAMPLE CODE
@Antonio Mele 2018-04-23 07:30:49
Thank you! Exactly what I need. I just changed: layoutManager.setFlexDirection(FlexDirection.ROW); layoutManager.setJustifyContent(JustifyContent.FLEX_START);
@Nilesh Rathod 2018-04-23 07:31:25
@AntonioMele welcome happy to help u my friend