2011-10-08 81 views
10

我想重複使用<include>標記的android應用程序中的一些佈局組件。我有不同的端口和土地佈局:layout_weight屬性<include>標記

  1. 端口:

    <LinearLayout a:layout_weight="1" a:layout_width="match_parent" a:layout_height="0dp"> 
    
        <include layout="@layout/calc_equals_button" a:layout_weight="4"/> 
        <include layout="@layout/calc_display"/> 
    
    </LinearLayout> 
    
  2. 土地:

    <LinearLayout a:layout_weight="1" a:layout_width="match_parent" a:layout_height="0dp"> 
    
        <include layout="@layout/calc_equals_button"/> 
        <include layout="@layout/calc_display"/> 
    
    </LinearLayout> 
    

主要區別是a:layout_weight="4",所以我想我的calc_equals_button組件在端口方向上較小。

的事情是,如果我嘗試嵌入calc_equals_button組件直接一切工作正常,例如:

<LinearLayout a:layout_weight="1" a:layout_width="match_parent" a:layout_height="0dp"> 
     <DirectionDragButton 
       xmlns:a="http://schemas.android.com/apk/res/android" 
       a:id="@+id/equalsButton" 
       a:text="=" 
       a:layout_width="match_parent" 
       a:layout_height="match_parent" 
       a:layout_weight="4" 
       style="@style/control_button_style" 
       a:onClick="numericButtonClickHandler"/> 

     <include layout="@layout/calc_display"/> 

    </LinearLayout> 

否則 - 不。

這裏是calc_equals_button.xml的樣本:

<DirectionDragButton 
    xmlns:a="http://schemas.android.com/apk/res/android" 
    a:id="@+id/equalsButton" 
    a:text="=" 
    a:layout_width="match_parent" 
    a:layout_height="match_parent" 
    style="@style/control_button_style" 
    a:onClick="numericButtonClickHandler"/> 

回答

26

的電流限制是你必須指定和layout_width爲layout_height其他layout_ *要應用的屬性。

+0

在ICS中,「當前」會改變嗎? –

+0

但是,這可以幫助解決這個問題? –

+0

@MichellBak不,這種限制仍然存在於ICS中。 –