2011-10-08 39 views
10

Tôi đang cố gắng sử dụng lại một số thành phần bố cục trong ứng dụng Android bằng cách sử dụng thẻ <include>. Tôi đã có cảng và đất khác nhau bố trí:thuộc tính layout_weight trong <include> thẻ

  1. Cảng:

    <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. đất:

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

khác biệt chính là a:layout_weight="4", vì vậy tôi muốn tôi Thành phần calc_equals_button nhỏ hơn trong định hướng cổng.

Vấn đề là nếu tôi cố gắng để nhúng calc_equals_button thành phần trực tiếp mọi thứ hoạt động OK, ví dụ .:

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

khác - KHÔNG.

Đây là mẫu 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"/> 

Trả lời

26

Một hạn chế hiện tại của bạn là phải định layout_width và layout_height cho layout_ khác * thuộc tính được áp dụng.

+0

"Hiện tại" như trong nó sẽ được thay đổi trong ICS? –

+0

Nhưng điều này có thể giúp gì cho vấn đề này? –

+0

@MichellBak Không, giới hạn này vẫn tồn tại trong ICS. –

Các vấn đề liên quan