2013-11-21 22 views
0

我發現我的活動的佈局是在兩個文件中定義的。這是我在/ RES /菜單main.xml中:Android - 佈局是在兩個獨立的文件中定義的?

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <!-- The main content view --> 
     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <!-- The navigation drawer --> 
     <ListView android:id="@+id/left_drawer" 
      style="@style/NavigationDrawer"/> 

      <!-- android:layout_width="240dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="0dp" 
      android:background="#111"/> --> 

    </android.support.v4.widget.DrawerLayout> 


    <item 
     android:id="@+id/add_button" 
     android:icon="@drawable/ic_action_new" 
     android:title="@string/add_button" 
     android:showAsAction="ifRoom"/> 

</menu> 

在這裏你可以找到我在/ RES /佈局/子activity_main.xml中。

正如你所看到的,例如,導航抽屜被定義兩次。這是必要的嗎?我是否必須將所有更改寫入這兩個文件?

+0

你能不能再使用使用含抽屜的Layout佈局? 請參閱 - http://developer.android.com/training/improving-layouts/reusing-layouts.html – ranjk89

回答

0

從main.xml中刪除以下內容。如果您在佈局文件中進行更改,則無需在main.xml中進行任何更改。

檢查下面的鏈接的佈局。 activity_main.xml是一個佈局文件

http://developer.android.com/guide/topics/ui/declaring-layout.html

main.xml是菜單資源

http://developer.android.com/guide/topics/ui/menus.html

<android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <!-- The main content view --> 
     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <!-- The navigation drawer --> 
     <ListView android:id="@+id/left_drawer" 
      style="@style/NavigationDrawer"/> 

      <!-- android:layout_width="240dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="0dp" 
      android:background="#111"/> --> 

    </android.support.v4.widget.DrawerLayout> 
+0

那麼,這似乎合乎邏輯。不知道如何將所有這些添加到菜單資源中。 – user2971688

+0

@ user2971688您無需將所有這些添加到菜單資源中。檢查mypost中的鏈接 – Raghunandan

相關問題