2011-10-08 15 views
10

Estoy tratando de reutilizar algunos componentes de diseño en la aplicación de Android usando la etiqueta <include>. Tengo portuarias y terrestres diferentes diseños:atributo layout_weight en <include> etiqueta

  1. Puerto:

    <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. del terreno:

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

principal diferencia es a:layout_weight="4", por lo que yo quiero que mi El componente calc_equals_button es más pequeño en la orientación del puerto.

La cosa es si intento para incrustar calc_equals_button componente directamente todo funciona bien, por ejemplo .:

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

lo contrario - NO.

Aquí es muestra de 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"/> 

Respuesta

26

Una limitación actual de es que se debe especificar layout_width y layout_height por otra layout_ * atributos que debe aplicarse.

+0

"Actual" como en ella se cambiará en ICS? –

+0

¿Pero cómo esto puede ayudar al problema? –

+0

@MichellBak No, esta limitación aún está presente en ICS. –

Cuestiones relacionadas