带左/右箭头的可滚动菜单栏
我希望创建一个类似于福克斯新闻应用程序顶部导航栏或菜单栏的功能。我开始使用图库自己编写代码,但我不确定如何在不需要时隐藏左右箭头。我还想知道是否必须为菜单项使用图像,或者是否可以只使用 TextView 或按钮,这样我就可以更改文本而无需修改图像。我在几个应用程序上看到过这种类型的导航,并且尝试了所有类型的搜索来尝试查找代码示例,但我不能为这种类型的可滚动菜单使用正确的名称,因为我找不到任何东西。如果有人有一个例子或提供文章的链接,我将不胜感激。
I am looking to create a navigation or menu bar similar to the functionality of the one at the top of the Fox News app. I started to code this myself using a Gallery but I'm not sure how to hide the left and right arrows when they are not needed. I was also wandering if you would have to use images for the menu items or if you could just use TextView or buttons so I could change the text without having to modify an image. I have seen this type of navigation on several apps and I tried all types of searches trying to find code examples but I must not be using the correct name for this type of scrollable menu because I couldn't find anything. If anyone has an example or provide a link to an article I would greatly appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看HorizontalScrollView。它是一种可以处理平滑滚动的布局,并且对于此操作来说,使用它可能比画廊要麻烦得多(出于类似的原因,我刚刚添加了一个布局)。
要处理左/右,请查看 setOnTouchListener。我不确定是否可以在不创建 HorizontalScrollView 的新子类来访问受保护方法的情况下获取当前滚动位置。然而,可能还有其他方法 - 我不需要添加按钮,所以我没有进行调查。
Look into HorizontalScrollView. It is a Layout that will handle the smooth scrolling and is likely to be much less of a hassle to work with than Gallery for this operation (I just added one for a similar reason).
To handle the left/right, look into setOnTouchListener. I'm not sure if you can get the current scroll position without making a new child class of HorizontalScrollView to access protected methods. There may be other ways, however - I didn't need to add buttons so I didn't investigate.