-1

I want to achieve something similar to the attached image

Android Image List

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
David Yap
  • 79
  • 2
  • 12

2 Answers2

1

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

0

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/

Martin De Simone
  • 2,108
  • 3
  • 16
  • 30