2012-07-23 91 views
2

我想在另一個佈局中包含一個佈局在我的一個應用程序中。但是我不能用標籤的幫助來做到這一點。它顯示錯誤消息,您必須指定佈局在包括標籤:。這裏有兩個XML文件:包括在另一個佈局中的佈局

<?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" > 

     <include 
     android:id="@layout/linearlayout" 


     /> 
</LinearLayout> 

這是第二之一:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearlayout" 
    android:orientation="vertical" 
    android:background="@color/LabelColorLight" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <naseeb.bar.DashboardLayout 
     android:id="@+id/dashboard" 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1"> 


     <Button 
      android:id="@+id/myprofile" 
      style="@style/HomeButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableTop="@drawable/ic_home_myprofile" 
      android:text="@string/home_myprofile" /> 


     <Button 
      android:id="@+id/beermail" 
      style="@style/HomeButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableTop="@drawable/ic_home_beermail" 
      android:text="@string/home_beermail" /> 


     <Button 
      android:id="@+id/beerstyles" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/HomeButton" 
      android:text="@string/home_beerstyles" 
      android:drawableTop="@drawable/ic_home_styles" /> 

     <Button 
      android:id="@+id/offlineratings" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/HomeButton" 
      android:text="@string/home_offlineratings" 
      android:drawableTop="@drawable/ic_home_offline" /> 

     <Button 
      android:id="@+id/places" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/HomeButton" 
      android:text="@string/home_places" 
      android:drawableTop="@drawable/ic_home_places" /> 

     <Button 
      android:id="@+id/top50" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/HomeButton" 
      android:text="@string/home_top50" 
      android:drawableTop="@drawable/ic_home_top50" /> 

     <Button 
      android:id="@+id/events" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/HomeButton" 
      android:text="@string/home_events" 
      android:drawableTop="@drawable/ic_home_events" /> 

     <Button 
      android:id="@+id/bycountry" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/HomeButton" 
      android:text="@string/home_bycountry" 
      android:drawableTop="@drawable/ic_home_bycountry" /> 
    <!-- <Button 
      android:id="@+id/naseeb" 
      android:drawable="@drawable/ic_launcher" 
      /> --> 

    </naseeb.bar.DashboardLayout> 
    </LinearLayout> 
    <!--  <Button 
     android:id="@+id/drinking_status" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 

     android:padding="10dip" 
     android:background="@color/Orange" 
     android:gravity="center" 
     android:visibility="gone" /> --> 

請告訴我如何解決這個問題。

回答

9

您的include標記應具有layout屬性。 id像其他任何元素一樣使用。

<include android:id="@+id/whatever" layout="@layout/linearlayout" /> 

此外,與其他標籤一樣,id屬性不是必需的。

+0

謝謝你,先生的工作 – 2012-07-23 13:42:28

+0

另外,包含「layout_width」和「layout_height」屬性是非常重要的。如果你不這樣做,你將無法覆蓋其他屬性,如果你需要。它只是忽略它們,除非指定了這兩個。 – DeeV 2012-07-23 13:43:10

+0

肯定先生,我會照顧它 – 2012-07-23 13:44:48