2013-03-10 40 views
0

我很困擾如何做到以下要求。如何在按下按鈕時顯示像這樣的選項菜單?

我需要做一個簡單的屏幕有兩個按鈕,就像這樣: 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> 

的子報頭的佈局基本相同。

我只是需要幫助,使每個按鈕的選項菜單。

在此先感謝!

回答

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/(您需要在此做一些修改)

第一個鏈接是你的案例中最有前途的。如果您將該頁面向下滾動到Gallery3D-like QuickActions部分,則會看到它與您希望應用程序的最終結果類似。當然,不言而喻,您仍然需要對網站上提供的來源進行修改。

希望這會有所幫助。 ;-)

+0

謝謝Siddharth!我會嘗試將這個例子改編成我的用例! – Lucas 2013-03-10 15:00:00

+0

@Lucas:很高興有幫助。祝你好運。 :-) – 2013-03-10 15:01:30

相關問題