<include>标签中的layout_weight属性

10
我正在尝试在安卓应用程序中使用<include>标签来重用一些布局组件。我已经有了不同的纵向和横向布局:

  • 纵向布局(Port):

  • <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>
    
  • 地点:

  • <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 组件在 port 方向上更小一些。
    问题是,如果我尝试直接嵌入 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"/>
    
    1个回答

    26

    目前的限制是,您必须为其他layout_*属性指定layout_width和layout_height才能应用它们。


    “Current”指的是它将在ICS中更改吗? - Michell Bak
    但是这怎么能帮助解决问题呢? - se.solovyev
    @MichellBak 不,ICS版本中仍存在此限制。 - Romain Guy
    4
    它解决了你的问题...你的包含标签必须指定重量的宽度和高度才能被考虑在内。 - Romain Guy

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接