Angry Birds like scrolling menu

前端 未结 3 2003
南旧
南旧 2020-12-24 03:50

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.

相关标签:
3条回答
  • 2020-12-24 04:16

    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.

    0 讨论(0)
  • 2020-12-24 04:20

    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.

    0 讨论(0)
  • 2020-12-24 04:24

    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?

    0 讨论(0)
提交回复
热议问题