I'm trying to reuse some layout components in android application using <include>
tag. I've got different port and land layouts:
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>
Land:
<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>
Main difference is a:layout_weight="4"
, so i want my calc_equals_button component to be smaller in port orientation.
The thing is if i try to embed calc_equals_button
component directly everything works OK, e.g.:
<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>
otherwise - NOT.
Here is sample of 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"/>
android:weightSum. Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
In a nutshell, layout_weight specifies how much of the extra space in the layout to be allocated to the View. LinearLayout supports assigning a weight to individual children. This attribute assigns an "importance" value to a view, and allows it to expand to fill any remaining space in the parent view.
A current limitation of is that you must specify layout_width and layout_height for other layout_* attributes to be applied.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With