views:

75

answers:

1

Hi Folks,

Can you tell me when we select an item in GalleryView its comes to the center of the screen how to restrict it? I want to just be there where i click that item. How? Simple words, I wanna horizontal Listview. How?

Thanks

A: 

HI, I would advise you check the "Hello, Gallery" on the google doc, it is very clear. Gallery is design to "display items in a horizontally scrolling list that locks the current selection at the center", as they say.
You just need to replace the ImageAdapter by TextAdapter, and put TextViews in it instead of ImageViews. It actually work exactly like a Listview. so you know how to do a Listview, this should be easy.

EDIT Here is I think a nice solution :
You need to change the style of the gallery. As default it is defined like that :

<style name="Widget.Gallery">
   <item name="android:fadingEdge">horizontal</item>
   <item name="android:gravity">center_vertical</item>
   <item name="android:spacing">-20px</item>
   <item name="android:unselectedAlpha">0.85</item>
</style>

So you need to create your own styles.xml in your folder gallery and put that in it :

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="gallery" parent="android:Widget.Gallery">
    <item name="android:fadingEdge">horizontal</item>
    <item name="android:gravity">center_vertical</item>
    <item name="android:spacing">0px</item> <!--This gives you no spacing between elements -->
    <item name="android:unselectedAlpha">1</item> <!--This puts all elements the same alpha -->
</style>
<resources>

This gives me this :
alt text
Now I'm sure we can get better result by playing with the various attributes of the gallery and the style, but I think this is a good lead for you ;)

Sephy
@sephy: you didnt get me properly. i dont want to come at the center of screen. is there any possible to do that?
Praveen Chandrasekaran
you meen you want the list to be horizontal but not having the zoom effect at the center?
Sephy
@sephy: yes absolutely.
Praveen Chandrasekaran
check my edit ;) you should like it
Sephy
@sephy: communication gap again. i would need to change the selected item should not be come to the center of the screen. It should be as it is. please check the cbc news app in the market it has the text gallery for to show the category. also check my another post. http://stackoverflow.com/questions/3237566/text-gallery-on-android
Praveen Chandrasekaran