Home:ALL Converter>How to made the height of the cardview/constaint layout have the same as width

How to made the height of the cardview/constaint layout have the same as width

Ask Time:2022-05-19T23:40:39         Author:BRDroid

Json Formatter

apologies if I am confusing it, in a constraint layout I have two card views which are equally spread out width wise based on constraints start and end.

The text thats going in those constraint layout text view is fixed size.

What I want to achieve is, the height of both card views to be same as the width of them.

we know that width of both will be the same cuz of constraints

but how can i set the height to be the same as with width.

basically want them to be two squares next to each other without setting hardcoded value.

Thanks in advance R

 <androidx.cardview.widget.CardView
            android:id="@+id/cvOne"
            style="@style/Tile"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="24dp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:focusable="true"
            android:visibility="visible"
            app:layout_constraintEnd_toStartOf="@+id/cvTwo"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cvChargeScheduleLayout">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/clOne"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/white_screen_bg"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:padding="8dp">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    
                    android:text="this is a fixed text"/>
            </androidx.constraintlayout.widget.ConstraintLayout>

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/cvTwo"
            style="@style/Tile"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="24dp"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:visibility="visible"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/cvOne"
            app:layout_constraintTop_toBottomOf="@+id/cvChargeScheduleLayout">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/clTwo"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/white_screen_bg"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:padding="8dp">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="this is a fixed text a bit longer....."/>
            </androidx.constraintlayout.widget.ConstraintLayout>

        </androidx.cardview.widget.CardView>

Author:BRDroid,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72307420/how-to-made-the-height-of-the-cardview-constaint-layout-have-the-same-as-width
yy