How to create horizontal menu in android?

末鹿安然 提交于 2019-12-11 10:43:47

问题


I am working on horizontal menu that will open on top of the screen. Layout is something like following,

|| < || Menu Item1 || Menu Item2 || Menu Item3 || > ||

I want to put this on top of the screen. It can have more than 3 menu item and it can traverse through previous and next arrow. I started with like this,

  • RelativeLayout ( width - fill_parent)

    • Gallery View ( Here i appended adapter )

There is two problem, - Gallery view contains the space before and after - While scrolling its item gets selected

Though its not ideal solution for this. How can i build custom component like this ? Any help appreciated.

Thanks


回答1:


If you want to use a gallery, you can override the onFling behaviour if you want to say slow down the fling or ignore vertical fling etc.

To disable the space, there is a an api call gallery.setSpacing()... To make the gallery not select when you are flinging use gallery.setCallbackDuringFling(false)

However, if all you want is a static menu that scrolls with the left and right buttons, I'd just subclass a LinearLayout and go from there.




回答2:


After some time i figured out other way. It worked for me perfectly.

HorizontalScrollView
         - LinearLayout (orientation: Hoz)
            - LinearLayout - Menuitem1 (orientation: Verticle)
                   - ImageView
                   - TextView
            - LinearLayout - Menuitem2 (orientation: Verticle)
                   - ImageView
                   - TextView
            - LinearLayout - Menuitem3 (orientation: Verticle)
                   - ImageView
                   - TextView



回答3:


Or you could use ViewFlipper or HorizontalScrollView. No subclassing needed for those.



来源:https://stackoverflow.com/questions/3832001/how-to-create-horizontal-menu-in-android

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