I need to place 6 squares horizontally across the width of the screen. I know that I can achieve this as follows:
<LinearLayout
android:weightSum="6"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/firstSquare"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="60dp"/>
<View
android:id="@+id/secondSquare"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="60dp"/>
.
.
.
</LinearLayout>
I want to ensure that the height of each View
in LinearLayout
is equal to its width.
Is there any way I can achieve it directly via XML
without using GridLayout, since weights are supported from API 21. My minimum SDK is API 16. I know that I can achieve this programmatically by getting the width of each View
object and then setting its height equal to its width, but I want to avoid it.