2012-10-11 79 views
5

我想在android中創建水平菜單。 Android支持可擴展列表視圖,可以垂直擴展,但我想水平擴展菜單。請參閱圖像水平菜單

enter image description here

說明:

在圖像菜單1,MENU2,菜單3是主菜單和S1,S2,S3是菜單1.分項目如果我主菜單及其子點擊項目必須展開。

回答

3

您可以將子菜單中的的LinearLayout和onClickListener

1

這是一個簡單的例子,添加具有View.VISIBLE/View.GONE發揮。 你應該自己完成它。

in xml。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/attachments_list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal"> 
    <Button 
     android:id="@+id/btn_menu1" 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:text="Menu1" 
     android:layout_weight="1" 
     /> 
    <LinearLayout 
     android:id="@+id/subview_menu1" 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:layout_weight="2" 
     android:visibility="gone" 
     > 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:text="S1" 
      android:layout_weight="1" 
      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:text="S2" 
      android:layout_weight="1" 
      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:text="S3" 
      android:layout_weight="1" 
      /> 
    </LinearLayout> 
    <Button 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:text="Menu2" 
     android:layout_weight="1" 
     /> 
    <Button 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:text="Menu3" 
     android:layout_weight="1" 
     /> 
    </LinearLayout> 

在btn_menu1 OnClickListener

public void onClick(View v) { 
    if (subview_menu1.isShown()) { 
     subview_menu1.setVisibility(View.GONE); 
    } 
    else{ 
     subview_menu1.setVisibility(View.VISIBLE); 
    } 
} 
+0

感謝我得到它,但我不得不產生random.I了有關如何做到這一點會管理它現在的感謝的想法。 –