我正在尝试使用< include>在
Android应用程序中重用一些布局组件.标签.我有不同的港口和土地布局:
>港口:
- <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>
主要区别是: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"/>
解决方法
当前的限制是必须为要应用的其他layout_ *属性指定layout_width和layout_height.