愤怒的小鸟喜欢滚动菜单

发布于 2024-10-24 12:42:04 字数 110 浏览 5 评论 0原文

当您启动“愤怒的小鸟”并点击“开始”时,您会看到一个水平滚动的菜单,其中有一条居中的图像,单击后您就可以开始游戏等等。我想知道如何制作一个与此类似的菜单,它可以横向滚动(水平)并显示可点击的图像?提前致谢!

When you start Angry Birds and hit play you are shown a horizontally scrolling menu with a centered line of images that once clicked on you can start the game and what not. I was wondering how to make a menu simular to this in that it scrolls sideways (horizontally) and shows tappable images? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仙气飘飘 2024-10-31 12:42:04

我认为您可以使用 Horizo​​ntalScrollView. 来完成此操作。 Horizo​​ntalScrollView 将是一个具有orientation:horizo​​ntal 的LinearLayout。它将包含 ImageView 或 ImageButton。为了实现《愤怒的小鸟》中的“对齐”效果,您必须为滚动视图设置一个 onTouchListener(),并在 ACTION_UP 部分中检查 hScrlView.getScrollX() 以查看哪个图像您最接近的图像,然后调用 hScrlView.scrollTo(x,y) 并将 x 参数设置为您最接近的图像的布局 x 值。

编辑:我个人从未使用过 GalleryView,而是基于 在本教程中,您似乎可以让它以这种方式工作。它可能会为您处理“捕捉”机制,这样您就不必制作自己的触摸监听器来做到这一点。我不确定是否可以在图库中设置图像之间的空间(《愤怒的小鸟》中的图片分布得相当远),但我确信如果您使用 Horizo​​ntalScrollView 和线性或相对布局,则可以。

I would think that you can accomplish this with HorizontalScrollView. The child of your HorizontalScrollView will be a LinearLayout with orientation:horizontal. It will contain ImageViews or ImageButtons. In order to achieve the 'snap to' effect that the one in Angry Birds has you'd have to set an onTouchListener() for your scroll view, and inside the ACTION_UP section you'd check hScrlView.getScrollX() to see which image you are closest to, then call hScrlView.scrollTo(x,y) and make the x parameter the layout x value of the image that you are closest to.

Edit: I have not ever personally used a GalleryView but based on this tutorial it seems like you could probably get it to work that way. And it might handle the 'snap to' mechanic for you so you wouldn't have to make your own touch listener to do that. Im not sure if you can set space between the images(the pictures in Angry Birds are spread out quite a bit) in a gallery though, which I know for sure that you can if you use a HorizontalScrollView and a Linear or Relative Layout.

沉默的熊 2024-10-31 12:42:04

您可以使用 Gallery 来做到这一点,并在适配器中将 TouchListener 添加到每个项目的 ImageView 中。这是最好的方法,因为当您滚动时,图库将支持每个图像居中。使用 Horizo​​ntalScrollView,您只能通过滑动进行滚动,并且菜单项不会集中。

You can do that using an Gallery, and in your adapter you add the TouchListeners to the ImageViews from each item. This is the best way, cause the Gallery will give support to each image get centered when you are scrolling. With HorizontalScrollView you got only scroll with fling, and the items of your menu will not be centralized.

做个少女永远怀春 2024-10-31 12:42:04

我自己还没有找到如何做到这一点,但这篇文章是一个好的开始:

如何在 Android 中制作水平 ListView?

I haven't been able to find how to do this myself, but this article is a good start:

How can I make a horizontal ListView in Android?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文