2012-12-11 4 views
2

총 5 개 항목이있는 옵션 메뉴를 만들고 싶습니다. 그러나 두 개의 항목이 한 줄에 나란히 있고 다른 세 항목이 각각 별도의 줄에 존재할 수 있습니다.Android 옵션 메뉴 - 한 행에 여러 항목이 있습니다.

문제는 어떻게 두 측면에서 하나의 라인 측에 존재하는 것입니다, ..... 자신의 라인에 기존 사용 사소한 개별적으로

를 항목을 추가하지만?

답변

-1

자체 행에있는 항목에는 세로 형 LinearLayout을 사용하고 나란히 있어야하는 두 항목에는 가로형 LinearLayout을 사용하십시오.

xml에서 LinearLayout 특성은 사용중인 버전에 따라 android:orientation="vertical" 또는 "horizontal"입니다.

0

불행히도 onCreateOptionsMenu(Menu menu)으로 생성 된 실제 옵션 메뉴는 노드를 가진 단순한 XML 인 menu 리소스를 사용합니다. Dialog 또는 PopupWindow을 사용하여 맞춤 메뉴를 만드는 경우 원하는대로 무엇이든 할 수 있습니다. 이 경우 가로가 LinearLayout이고 가로가 LinearLayout 인 레이아웃을 만들고 일반 요소와 함께 배치 된 side-by-side 요소가 들어 있습니다.

<?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> 
관련 문제