2012-12-11 89 views
2

我想创建一个总共包含5个项目的选项菜单。但是,我想在一行中并排存在两个项目,其他三个项目可以存在于各自的行中。Android选项菜单 - 单个行中的多个项目

单独添加项目现有的对自己行是微不足道的使用.....

但是,问题是如何有2个并排在一个线路侧存在吗?

回答

-1

使用一个垂直的LinearLayout作为它们自己的线条存在的项目和一个水平的LinearLayout作为必须并排存在的两个项目。

在xml中,LinearLayout属性为android:orientation="vertical""horizontal",具体取决于您正在使用的属性。

0

不幸的是,一个真正的选项菜单(由onCreateOptionsMenu(Menu menu)创建)需要一个menu资源,它只是一个带有item节点的XML。如果您使用DialogPopupWindow创建自定义菜单,那么您可以从字面上做任何你想做的事情。在这种情况下,请创建一个垂直排列的布局,其中包含与常规元素相交叉的并排元素的一些水平排列LinearLayout

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/Button01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/Button02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 
    </LinearLayout> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 
    </LinearLayout> 
</LinearLayout>