2012-10-11 67 views
5

Tôi muốn tạo menu ngang trong Android. Android hỗ trợ chế độ xem danh sách có thể mở rộng mở rộng theo chiều dọc nhưng tôi muốn mở rộng các menu theo chiều ngang. Vui lòng tham khảo hình ảnhNgang Menu

enter image description here

Mô tả:

Trong những hình ảnh Menu1, menu2, menu3 là menu chính và s1, s2, s3 là mục phụ của menu 1. Nếu tôi nhấp vào menu chính phụ của nó các mục phải được mở rộng.

Trả lời

3

Bạn có thể đặt các menu con trong một LinearLayout và thêm chơi với View.VISIBLE/View.GONE trong OnClickListener

1

Đó là một ví dụ đơn giản. bạn nên hoàn thành nó một mình.

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> 

trong btn_menu1 OnClickListener

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

cám ơn tôi đã nhận nó, nhưng tôi phải làm ra rằng random.I đã có ý tưởng về làm thế nào để làm điều đó sẽ quản lý nó bây giờ nhờ. –

Các vấn đề liên quan