ActionBar 中的全角微调器
我真的希望我的应用程序有一个 Spinner,它可以拉伸 ActionBar 的整个长度,就像 Gmail 4.0 中的那样。有人知道如何实现这一目标吗?即使我在 Spinner 布局资源中设置“match_parent”,它也不会填充整个栏。最好,我希望能够让它填满除我的操作项之外的整个栏,而不是也使用拆分操作栏。
编辑:请参阅下面我的答案,了解使用自定义视图时使用内置操作栏或 hankystyles' 的实现
I'd really like my app to have a Spinner which stretches the entire length of my ActionBar, like the one in Gmail 4.0. Anyone know how to achieve this? Even if I set "match_parent" in the Spinner layout resource, it doesn't fill the entire bar. Preferably, I'd like to be able to have it fill the entire bar except for my action items, rather than using the split actionbar as well.
EDIT: see my answer below for an implementation using the built-in actionbar, or hankystyles' when using a custom view
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有点烦人的是我刚刚完成了它,但这里有一种使用操作栏中内置的微调器来完成此操作的方法。您需要做的就是使微调器项目的主容器成为
RelativeLayout
并将其重力设置为 fillHorizontal,如下所示:并按如下方式初始化适配器:
然后提供跨越整个操作栏的所需微调器(除了对于操作按钮):
Bit annoying that I've just done it, but here is a method of doing it using the built-in Spinner in the action bar. All you need to do is make your spinner item's main container a
RelativeLayout
and set its gravity to fillHorizontal, like so:And initialising the Adapter as so:
which then gives the required spinner spanning the entire actionbar (except for the action buttons):
我的 Gmail 应用程序上的微调器也跨越了操作栏的整个宽度。这个解决方案对我有用:
旋转器布局如下所示:
我怀疑通过覆盖默认操作栏导航样式像这样,但我无法立即使其工作。
The spinner on my gmail app also spans the entire width of my action bar. This solution worked for me:
Where the spinner layout is like so:
I suspect there's a better solution to be had by overriding the default action bar navigation style like this but I couldn't immediately get that working.
尝试将微调器的背景设置为图像文件。默认背景导致了我的布局问题,但是当我将其设置为我自己的空白 1x1 像素的 png 时,它按照我的意愿填充了我的布局。如果这有效,您可能需要创建一个适合您的自定义图像。我希望这有帮助。
Try setting the background of the spinner to an image file. The default background has caused me layout issues, but when I set it to my own png of a blank 1x1 pixle it filled my layout as I wanted. If that works you may have to create a custom image that works for you. I hope that helps.
如果 Spinner 中有 TextView,则可以将 minEms 设置为较高的值。这是我探索过的最简单的解决方法:
If you have a TextView inside your Spinner, you can set the minEms to a high value. This is the easiest workaround I explored: