I want a layout that will display images without knowing how many. First i thought of a ScrollView, but don't know how to add different images to it. How can that be done? Or is there any other solution?
-
Post relevant code whatever you tried. – Jay Rathod Jul 28 '16 at 13:24
-
A scrollview allows you to touch the screen and scroll if there is more content then there is space on the page. Inside you can have an ImageView, textview, edittext, so on.. It is not specific to images – Michael Jul 28 '16 at 13:26
3 Answers
How can that be done?
Have the ScrollView
wrap around a vertical
LinearLayout
, into which you add your ImageView
widgets.
Or is there any other solution?
ListView
. GridView
. RecyclerView
. ViewPager
. And so on.

- 986,068
- 189
- 2,389
- 2,491
-
-
@OleksandrZakrevskiy: Create the `ImageView` widget. Configure it (e.g., use Picasso to load your image into it asynchronously). Call `addView()` on the `LinearLayout`, passing it the `ImageView` and a suitable `LinearLayout.LayoutParams`. Do this for each image. – CommonsWare Jul 28 '16 at 13:34
Depending on how you want to display the images, you can also use GridView : Grid View Android Developpers
There is an example : Gridview with two columns and auto resized images
You don't need to use ScrollView
or know the amount of images you're gonna show. Just use a ListView
with an ArrayAdapter
that binds a List
of Bitmap
s (images) to your ListView
(each item of your ListView
is an ImageView
). Each time you add a new image to your list, just call notifyDataSetChanged()
method of your adapter, that's gonna update your ListView
.
Just google for a relevant tutorial. You're gonna see lots of examples.

- 5,973
- 3
- 42
- 73