0

I am working on an app which should display several same size images on the screen. But it should only display only so much images as possible without offering scrolling.

E.g. On a "big" tablet it could display 10x10 Imageviews (screen is large, so there is much space for pictures)

On a "big" phone there might be enough space to display 6x6 ImageViews, so it should only display a 6x6 array of images.

On a small phone there is propably only space for 4x4 ImageViews, so it should only display this.

How can I make this in Android? I know about "layout-large", ... but if i make a special fixed xml-layout for a "large" device, it would not fit all devices correct. E.g. a Galaxy Nexus is a "normal" device and so is a Nexus One, but there would be at least be space for one or two more imageview rows on a Galaxy Nexus than on a Nexus One. So do I have to measure in code somehow how big the resolution is and display some TableRows accordingly? Or is there a special way how I can manage this?

Toni4780
  • 443
  • 1
  • 8
  • 14

2 Answers2

0

you can query the properties of the screen of the device such as size, density etc. Once you know the size you can choose the layout to use.

Take a look at this stackoverflow post. Android: how to get screen dimensions

Community
  • 1
  • 1
Orlymee
  • 2,349
  • 1
  • 22
  • 24
0

You should use a GridView to manage this.

GridView Android Developers

Edit: And indeed as Tomasz Gawel said: notice the GridView's android:numColumns="auto_fit" xml attribute

Edit: since you don't want it to be scrollable, you can just get the screensize, divide it by the size of your items, and put in only as much items as you want to display in the gridview. The gridview will only scroll when it has more items than it can display.

getResources().getDisplayMetrics().widthPixels and heightPixels
vanleeuwenbram
  • 1,289
  • 11
  • 19
  • and notice the GridView's `android:numColumns="auto_fit"` xml attribute – Tomasz Gawel Jun 01 '12 at 23:33
  • Ok, but I want a non-scrollable list. As the GridView Documentation notes it represents "a two-dimensional, scrollable grid". I just want a grid which is non-scrollable. It should display 4x4 images on a regular phone and 10x10 images on a tablet. If enough space is left for a row, then a new row should be added, otherwise not – Toni4780 Jun 02 '12 at 12:20