Search code examples
androidxmlcheckboxandroid-linearlayout

How to make two vertical rows of checkboxes pararell to each other? android


This is part of my code. Everything would work perfectly if not that some of the checkboxes' texts take two lines and some one line. How do I make them pararell to each other?

            `<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_1"
                    android:textAppearance="?android:textAppearanceMedium"/>

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_2"
                    android:textAppearance="?android:textAppearanceMedium"/>

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_3"
                    android:textAppearance="?android:textAppearanceMedium"/>

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_4"
                    android:textAppearance="?android:textAppearanceMedium"/>

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_5"
                    android:textAppearance="?android:textAppearanceMedium"/>

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_6"
                    android:textAppearance="?android:textAppearanceMedium"/>

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_7"
                    android:textAppearance="?android:textAppearanceMedium"/>

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/answer9_8"
                    android:textAppearance="?android:textAppearanceMedium"/>
            </LinearLayout>
        </LinearLayout>`

This is part of my code. Everything would work perfectly if not that some of the checkboxes' texts take two lines and some one line. How do I make them pararell to each other?


Solution

  • Assign a specific height to the checkboxes say like 100dp (accordingly to your longest text) just make sure it adjusts on different resolutions to make sure the text doesn't overlap the layouts.