0

I am trying to build a row of images. I want the number of images to increase based on screen width. For example, in portrait mode there may be 3 images present, but in landscape there would be five.

I have tried using a GridView, but I am having trouble stopping it from being populated after the first row has been filled (it goes to the next row). Is there an alternative view I should be using or is a GridView the right approach?

Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60
  • u want to scroll in which direction ? – KOTIOS Aug 16 '14 at 18:50
  • No scrolling - this design is for decorative purposes – Daiwik Daarun Aug 16 '14 at 18:51
  • why not creating one layout for Portrait and one Layout for Landscape? – Itzik Samara Aug 16 '14 at 18:52
  • Good idea, but the images are square in shape - I don't want to stretch them to fill an area (picture my end goal as being a strip of bathroom tiles - I want to keep adding tiles until I reach the other side) – Daiwik Daarun Aug 16 '14 at 18:55
  • Maybe set a static height for a div container for them, and setting overflow:hidden for the div (all 5 images would appear, but 2 of them would not be on screen on the thinner view) - you would just have to adjust the size of the images and the spacing between them - the idea Itzik had would be possible if you have a media query for orientation:landscape and another for orientation:portrait -- so you could control spacing and sizing that way - you could also give them different id's and using a media query like I just mentioned, in portrait mode set display:none to two of the image id's – Jeff Clayton Aug 16 '14 at 19:00

2 Answers2

0

If you only want 1 row, then use a LinearLayout. If it needs to scroll, embed it in a HorizontalScrollView.

If you aren't scrolling you can then inflate and add each image, depending on available space.

You could make it more complex by creating custom classes, etc.

You can also try the Two-Way GridView (I've used it - it works great)

How to make grid-view horizontally scrollable in android

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
0

I have found a suggestion based off of this. Once a max width has been exceeded on the LinearLayout, simply stop adding to it!

Community
  • 1
  • 1
Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60