按下按钮时如何显示这样的选项菜单?

时间:2013-03-10 13:49:08

标签: java android menu

我无法确定如何执行以下要求。

我需要用两个按钮制作一个简单的屏幕,如下所示: enter image description here

屏幕的那部分已经完成。

对我来说最难的是制作两个按钮的行为 当他们被按下时在这种情况下,他们必须显示一个选项菜单 像这样:

按钮1按下: enter image description here

按钮2按下:

enter image description here

我还没有开始编程菜单,但如果它有帮助,这是 屏幕布局(没有按钮)。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/grayBackgound"
    tools:context=".MenuActivity" >

    <include android:layout_width="match_parent" layout="@layout/header" />
    <include android:layout_width="match_parent" layout="@layout/loggedin_subheader"/>

</LinearLayout>

标题的布局:

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

    <ImageView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/header"
        android:contentDescription="@string/header" 
     />


     <ImageButton 
            android:id="@+id/btnClose"
            android:src="@drawable/btn_close"
            android:contentDescription="@+string/salir"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="260dp"
      />


</FrameLayout>

子标题的布局几乎相同。

我只需要帮助就可以为每个按钮制作选项菜单。

提前致谢!

1 个答案:

答案 0 :(得分:3)

您要实现的菜单通常称为QuickAction Dialog。有几个教程可供选择。

为了帮助您入门,请点击以下链接:

  1. http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

  2. https://github.com/ruqqq/WorldHeritageSite(这不是教程本身,但具有QuickAction Dialog的完整实现)

  3. https://code.google.com/p/simple-quickactions/(您需要对此进行一些修改)

  4. 在您的情况下,第一个链接是最有希望的。如果您将该页面向下滚动到与Gallery3D类似的QuickActions 部分,您会发现它类似于您希望应用中的最终结果。当然,不言而喻,您仍然需要对网站上提供的资源进行修改。

    希望这会有所帮助。 ; - )