Depending on how variable the heights of the elements are, you have several options:
If you want to make a GridView with many height variations (like Pinterest), you should play with StaggeredGridView - as far as I can tell, this is the best open source solution right now.
In the image you posted, it looks like there are parent lines with children with variable heights - this is a slightly simpler problem to solve, and they can be simulated using the usual ol ' ListView and a subclass of BaseAdapter . Writing code for this is too important for an SO response, but I will give you an overview of how I can achieve this effect.
BaseAdapter must determine the rough layout of each row in advance so that it can report to the list about how many rows it will need β you need to override getCount() .- In the
getView() your adapter, you LinearLayout one LinearLayout (or maybe use a convertView if it has been redesigned) and add as many children (again, more LinearLayouts ) as you need for width (you have to figure this out at runtime, unless you just want to create a version of your phone and tablet). - Each
LinearLayout that is added to the row must be set to weight = 1 to stretch the entire width of the parent row. There are 3 columns in the screenshot you posted (the third one is disabled). - Each child
LinearLayout that you just added to a row represents a column. You have to set the orientation to vertical, being columns! - In each column, if you have to add one child, you will have a gridview.
- If you want to achieve the effect above, you can add more elements to each column.
- For example, row 1, column 1 has one big child. Columns 2 and 3 in row 1 have 2 children with half height.
source share