Android选项菜单-单行中有多个项目
我想创建一个选项菜单,共有5项。但是,我希望有两个项目并排存在一行中,其他3个项目可以在各自的单独行中存在 使用….添加单独存在于其自己行中的项非常简单Android选项菜单-单行中有多个项目,android,android-layout,android-ui,Android,Android Layout,Android Ui,我想创建一个选项菜单,共有5项。但是,我希望有两个项目并排存在一行中,其他3个项目可以在各自的单独行中存在 使用….添加单独存在于其自己行中的项非常简单 但是,问题是如何使2并排存在于一行中?对其自身行中存在的项目使用垂直线性布局,对必须并排存在的两个项目使用水平线性布局 在xml中,LinearLayout属性是android:orientation=“vertical”或“horizontal”,具体取决于您使用的是哪一个。对于在各自行上存在的项目,使用垂直线性布局;对于必须并排存在的两个项
但是,问题是如何使2并排存在于一行中?对其自身行中存在的项目使用垂直线性布局,对必须并排存在的两个项目使用水平线性布局
在xml中,LinearLayout属性是
android:orientation=“vertical”
或“horizontal”
,具体取决于您使用的是哪一个。对于在各自行上存在的项目,使用垂直线性布局;对于必须并排存在的两个项目,使用水平线性布局
在xml中,LinearLayout属性是android:orientation=“vertical”或
“horizontal”
,这取决于您使用的是哪一个。不幸的是,一个真正的选项菜单(由onCreateOptions菜单(菜单菜单菜单)
创建)需要一个菜单
资源,它只是一个带有项
节点的xml。如果您使用对话框
或弹出窗口
创建自定义菜单,那么您可以随心所欲地执行任何操作。在这种情况下,创建一个具有垂直LinearLayout
和一些水平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>
不幸的是,真正的选项菜单(由创建选项菜单(菜单菜单菜单)创建)需要一个
菜单
资源,它只是一个带有项
节点的XML。如果您使用对话框
或弹出窗口
创建自定义菜单,那么您可以随心所欲地执行任何操作。在这种情况下,创建一个具有垂直LinearLayout
和一些水平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>