TextView on Horizontal ScrollView in android?

岁酱吖の 提交于 2019-12-08 12:17:14

问题


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


回答1:


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 http://img249.imageshack.us/img249/1893/testgallery.png
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 ;)



来源:https://stackoverflow.com/questions/3318617/textview-on-horizontal-scrollview-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!