Petr Peller
Petr Peller

Reputation: 8846

Table with variable column width per row (similar to UICollectionView for iOS)

Is there an equivalent for iOS UICollectionView in Android SDK?

I need to implement similar "table" layout as below, but as there are many cells (user will scroll the screen to view all) I need cell re-using for performance reasons.

+-----------------+----------+--------+
| cell 1          | cell 2   | cell 3 |
+-----------------+--+-------+--+-----+
| cell 4  | cell 5   | cell 6   |
+---------+---+------+-----+----+---------+
| cell 7      | cell 8     | cell 9       |
+-------------+------------+--------------+

I was thinking to use separate GridView for each row, but I need to scroll all table at once and I am not sure if cell re-using will work properly that way.

What is the best way to implement the table above?

Upvotes: 11

Views: 1916

Answers (3)

Shreyash Mahajan
Shreyash Mahajan

Reputation: 23606

I am not sure, but you can find the Solution for your issue here.

I think Bucket List Adapter is the Solution of your question. Please try with implementing it and let me know.

Feel free to comments. Enjoy Coding. :)

UPDATED

You Can also do like as you have said. Just create Dynamic TableLayout while User scrolling from down to up. So it will not take much Memory and will also display the data based on your custom view. In such way you will have Scroll will all the cell and also have solve the memory issue.

Upvotes: 1

Aswathy P Krishnan
Aswathy P Krishnan

Reputation: 12508

I think the StaggeredGridView or QuiltView libraries will help you solve your issue. Using these libraries, we can arrange the images according to the width and height

If you are using quilt view, you can arrage it in different styles by changing the ScaleType, etc.

I haven't tried the TwoWayGridView but is worth trying. I hope this helps.. :)

Upvotes: 1

Ben Max Rubinstein
Ben Max Rubinstein

Reputation: 1813

If you can set the cells to a predefined width, you should check out TwoWayGridView.

Otherwise, what you are looking for is in the AOSP's experimental branch and it's called StaggeredGridView. They have started the implementation but it's quite young and unprepared, though it may give you a hint as to where to start.

Generally, there are different approaches to this, and from my experience you may end up in having to write a good robust view recycler and re-user yourself, to be able to rely on existing API and widgets, where you will only have to calculate the width of the scroll and lay the views as they detach or need to be attached to your containers upon scrolling events.

Upvotes: 4

Related Questions