1

May be i am asking wrong question. But please guys help me out. i want to display images in Grid View format. I have 5 images now i want to display these images like this(in single row scroll able).

image1  image2 image3  image4  image5

But in mobile we can display 2 or 3 at a time. Can we set the number of rows in Grid View like numColumn:2? Thanks for considering.

rupesh
  • 2,865
  • 4
  • 24
  • 50

2 Answers2

1

GridView is not really designed for this purpose, it is designed to display an indefinite amount of data in an efficient scrolling manner. If you want to create a static layout where you can discretely place items at specific locations, you should be looking at GridLayout or TableLayout instead.

from

How to set a fixed number of rows in android gridView?

Community
  • 1
  • 1
gaurav5430
  • 12,934
  • 6
  • 54
  • 111
1

If you need to display a fixed number of images (for example using ImageView) horizontally, the best solution is using HorizontalScrollView with a single horizontal LinearLayout child, which will contain the images. It will look something like this:

<HorizontalScrollView android:layout_width="match_parent"
                      android:layout_height="wrap_content">
    <LinearLayout android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal">
        <ImageView ...
                   ... />
        <ImageView ...
                   ... />
        ...
    </LinearLayout>
</HorizontalScrollView>
GareginSargsyan
  • 1,877
  • 15
  • 23
  • i am using gallery working fine but only one image it displaying at a time. what should i do? i want to display minimum 2? – rupesh Dec 24 '13 at 05:19
  • I would not suggest using Gallerty. It is deprecated. You can find custom open-source layouts with similar functionality. Another solution would be using a ViewFlipper which will contain LinearLayouts each containing two images, – GareginSargsyan Dec 24 '13 at 10:17
  • in my case no of images is not confirm. Could u please provide me some good resources or sample code if u have already done it.Thanks for your help. – rupesh Dec 24 '13 at 10:29
  • What do you mean by 'no of images is not confirm' ? – GareginSargsyan Dec 24 '13 at 10:31
  • i meant i am getting form server can be 10 or 100. i want to display in horizontal scrollbale view in single row. and center image will be selected by default. – rupesh Dec 24 '13 at 10:34
  • like this http://stackoverflow.com/questions/20583033/android-cover-flow-gallery-and-remove-space-between – rupesh Dec 24 '13 at 10:37
  • You can try using this layout: http://www.androidviews.net/2012/10/android-coverflow/ – GareginSargsyan Dec 24 '13 at 10:46
  • But in last Comment is still saying that "sadly it extends from Gallery too, so it has all the weirdness around it." – rupesh Dec 24 '13 at 10:54
  • Do we have better option from this. I am worrying about that. lot of comments over there "Library needs a serious update: 1.Uses a deprecated class. 2.Doesn’t scale in the correct way. should use relative sizes for : image size, gap, reflection , based on the size that the coverFlow view itself has, and not a precise size. 3.Has a serious bug: when the image size is set to something different from the default value, after scrolling , the centered image gets tilted." – rupesh Dec 24 '13 at 10:57
  • i want to display n number of images in horizontal scroll view and minimum 3 images at a time. How can i do this?? – rupesh Jan 03 '14 at 04:31