私の知る限り、メニューで改行を強制する方法はありません。いくつかのシナリオを考えると、これは実際に理にかなっています。
たとえば、横向きのタブレット (Galaxy Tab など) があるとします。水平方向のスペースがかなり広く、高さが比較的小さいです。そのため、このような場合に改行を強制するとスペースの無駄になります。

これについてさらに調査を行いました。MenuBuilder
オプションメニューを管理するために使用されるというクラスがあります。レイアウト リソースを使用してicon_menu_layout
メニューを描画します。このリソースは次のとおりです。
<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
れる興味深い関数が 1 つ見つかります。layoutItems
メニュー項目の幅を人為的に増やすことによってのみ、この関数のロジックに影響を与えることができます。改行はありません。
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;
}
}
}
たとえば、最初の項目の幅を広げると、メニューに 2 行が表示されます。しかし、さまざまなデバイスで使用されるテキスト スタイル、サイズ、およびフォントを予測できないため、これはおそらく望ましくありません。
