2

Gallery view displays images in a horizontal manner.

Let us consider at landscape mode. The first image is displayed at the centre of the screen. When the user scrolls at the left of the screen, the first image moves to the left of the screen, the second image occupies the centre of the screen. Also, it automatically positions the image at the centre.

Is there any way by which

  1. I can stop displaying the image at the centre.

  2. For example, if I scroll the image to a position, it should stop auto movement & alignment & stop where I have scrolled.

Kindly provide your suggestions. Thanks in advance.

Mikael Östberg
  • 16,982
  • 6
  • 61
  • 79
chiranjib
  • 5,288
  • 8
  • 53
  • 82

1 Answers1

1

Gallery will always be a center-locked Layout. You cannot change that.

If you do not have a lot of images to display you can put them in an horizontal LinearLayout and put the layout inside an HorizontalScrollView. But beware, you will consume a lot of ressources doing this because all child views will be created.

ListView and Gallery layouts have optimisations that allow them to recycle child views while scrolling.

If you need the recycling, you might need to reimplement an horizontal ListView of your own, without the scroll system of the Gallery. See this excellent Stackoverflow question on this subject: How can I make a horizontal ListView in Android?

Community
  • 1
  • 1
pcans
  • 7,611
  • 3
  • 32
  • 27
  • 2
    Gallery does not recycle views. – Jeffrey Blattman Apr 22 '11 at 19:51
  • 1
    It doesn't really do view recycling - it creates a new view for EVERY item in your adapter - note how it always passes `null` to `getView` so you can never re-use `convertView`. However if it's showing an item it's already shown it does get that view from the recycler, rather than make a new one (since they'd be exactly the same) – Joseph Earl Apr 26 '11 at 10:57
  • 2
    put some breakpoints in your adapter. you see it calling getView() an astounding number of times. the Gallery widget really is a terrific piece of junk. – Jeffrey Blattman Apr 26 '11 at 15:25
  • 1
    I took time to really read the code, you two are right, gallery will create a new view for each child. thank you for pointing it to me. – pcans Apr 28 '11 at 16:00