I have the following Android menu XML file:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/programma" android:icon="@android:drawable/ic_menu_agenda" android:title="@string/programma" /> <item android:id="@+id/settings" android:icon="@android:drawable/ic_menu_preferences" android:title="@string/settings" /> <item android:id="@+id/help" android:icon="@android:drawable/ic_menu_help" android:title="@string/help" /> </menu>
这给了我在一行三个菜单按钮。不过,我要划分为两线,2个按钮的第一行,并在整个底部行的帮助按钮。我已经尝试过分组的前两个,但是这并没有这样的伎俩。 我怎么能强制换行的XML?
That gives me three menu buttons on one line. However, I want to divide them in two lines, with 2 buttons on the first row, and the help button on the entire bottom row. I already tried grouping the first two, but that didn't do the trick. How can I force a line break in the XML?
据我所知是没有办法来强制换行的菜单。这实际上是有道理的,如果你考虑一些方案。
As far as I know there is no way to force line break in menu. This actually makes sense if you consider some scenarios.
例如,假设你有平板电脑(例如银河标签)的横向方向。它有相当多的水平空间和相对较小的高度。因此,这将是一个浪费的空间,如果你强迫在这种情况下换行符。
For example, imagine you have tablet (for example, Galaxy Tab) in landscape orientation. It has quite a lot of horizontal space and relatively small height. So, it would be a waste of space if you force line break in such case.
我已经做了这方面的详细调查。有一类名为 使用MenuBuilder 它是用来管理选项菜单。它使用 icon_menu_layout 布局资源来绘制菜单。 这里是此资源:
使用MenuBuilder
icon_menu_layout
I've done more investigation on this. There is a class called MenuBuilder which is used to manage options menu. It uses icon_menu_layout layout resource to draw menus. Here is this resource:
MenuBuilder
<com.android.internal.view.menu.IconMenuView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/icon_menu" android:layout_width="match_parent" android:layout_height="wrap_content" android:rowHeight="66dip" android:maxItems="6" android:maxRows="2" android:maxItemsPerRow="6" />
如果你遵循的 IconMenuView 实现,你会发现一个有趣的功能叫做 layoutItems 这是用来计算布局菜单项。您只能通过人为地增加宽度的菜单项会影响此功能的逻辑。不换行是可用的。
IconMenuView
layoutItems
And if you follow to IconMenuView implementation, you'll find one interesting function called layoutItems which is used to calculate layout for menu items. You can only influence this function's logic by artificially increasing width of menu items. No line breaks are available.
private void layoutItems(int width) { int numItems = getChildCount(); if (numItems == 0) { mLayoutNumRows = 0; return; } // Start with the least possible number of rows int curNumRows = Math.min((int) Math.ceil(numItems / (float) mMaxItemsPerRow), mMaxRows); /* * Increase the number of rows until we find a configuration that fits * all of the items' titles. Worst case, we use mMaxRows. */ for (; curNumRows <= mMaxRows; curNumRows++) { layoutItemsUsingGravity(curNumRows, numItems); if (curNumRows >= numItems) { // Can't have more rows than items break; } if (doItemsFit()) { // All the items fit, so this is a good configuration break; } } }
因此,举例来说,如果增加宽度第一个项目,你会得到菜单中的两行。但是,这可能是不可取的,因为你不能predict文字样式,大小和字体,将在不同的设备上使用。
So, for example, if you increase width of first item, you'll get two lines in menu. But this is probably undesirable, because you can't predict text style, size and font that will be used on different devices.
相关推荐
北京大北农科技集团股份有限公司(北京农业高科技企业)
唐诗(唐朝诗歌通称)
中华保健医学杂志(中央军委后勤保障部卫生局保健办主办的报刊)
临戴进谢安东山图(2023最新临戴进谢安东山图百科介绍)
存贷款基准利率(2023最新存贷款基准利率百科介绍)
卢世昌(丰县知县)
白酒塑化剂事件(社会事件)
泸州大贰(四川泸州地区流行的棋牌游戏)
如何创建在淘汰赛映射类型化的集合类?淘汰赛、类型
检查一个web服务存在存在、web
请CardView的ImageView的合适宽度宽度、合适、CardView、ImageVie
在.NET非矩形形式平滑边缘矩形、平滑、边缘、形式
婚礼的祝福文案句子 适合婚礼的祝福短信_婚礼祝福短语 适合祝福婚
新春祝福贺年卡 _ 快乐幸福,身体健康
1. Bauer_2. CCM
两个点是多少钱_60万两个点是多少钱
秋季四大养生方法_秋季中医养生方法是什么
男生怎么瘦上半身_男生应该如何瘦上半身
月经期间吃什么粥最好呢?_月经期间吃什么食物好
沱江(沱江在哪里哪个省的)
最新文章
约翰·沃尔(美国男子篮球运动员)
微量元素地球化学(2023最新微量元素地球化学百科介绍)
陈平(广东省湛江市霞山实验中学校长)
Sometimes when We Touch(Dan Hill演唱的英文歌曲)
人的对象化(人的对象化)
经济难民(经济难民)
摇篮的Android版本为不同的处理器架构摇篮、架构、处理器、不
把按钮在屏幕使用的LinearLayout底部?按钮、屏幕、LinearLayout
使用的FrameLayout时相机preVIEW拉伸相机、FrameLayout、preVIEW
Java中哪些情况需要同步方法访问?情况、方法、Java
如何找出谁的ROM提供者?提供者、谁的、ROM
是否退出批处理文件中的for循环?批处理文件、for
如何使用通用处理程序(ASHX)在ASP.NET MVC?如何使用、程序、ASHX、MV
不知有没有无限流的玄幻小说_艳遇玄幻小说有没有
为什么人在吃完硫酸镁之后会导泻?_为什么吃完硫酸镁之后会导泻?
南瓜蜜豆土司的做法_牛奶蜜豆土司的做法
男人这物吃多了没好处伤了你的肾!_男人这物吃多了竟然会没孩子
孩子经常感冒怎么办_孩子肠胃感冒症状严重吗
豆腐干热量是多少?_豆腐干热量
个性发展自我评价范文(个人简历自我评价简短精选20篇)