简体   繁体   English

Android中水平ScrollView上的TextView?

[英]TextView on Horizontal ScrollView in android?

Can you tell me when we select an item in GalleryView its comes to the center of the screen how to restrict it? 当我们在GalleryView选择一个项目时,您能告诉我它如何出现在屏幕中央吗? I want to just be there where i click that item. 我只想在那里单击该项目。 How? 怎么样? Simple words, I wanna horizontal Listview. 简单地说,我想使用水平Listview。 How? 怎么样?

Thanks 谢谢

HI, I would advise you check the "Hello, Gallery" on the google doc, it is very clear. 嗨,我建议您检查一下Google文档中的“你好,画廊” ,这非常清楚。 Gallery is design to "display items in a horizontally scrolling list that locks the current selection at the center", as they say. 正如他们所说,Gallery被设计为“在水平滚动列表中显示将当前选择锁定在中心的项目”。
You just need to replace the ImageAdapter by TextAdapter, and put TextViews in it instead of ImageViews. 您只需要用TextAdapter替换ImageAdapter,然后将TextViews而不是ImageViews放在其中即可。 It actually work exactly like a Listview. 实际上,它的工作原理完全类似于Listview。 so you know how to do a Listview, this should be easy. 所以您知道如何做一个Listview,这应该很容易。

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 : 因此,您需要在文件夹库中创建自己的styles.xml并将其放入其中:

<?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 替代文字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 ;) 现在,我敢肯定,通过使用画廊的各种属性和样式,我们可以得到更好的结果,但是我认为这对您来说是一个很好的线索;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM