title: How to make CardView width match it height?
body: <p>I have a CardView in a LinearLayout. The Layout reserves 1/5 of the screen for the CardView and 4/5 of the screen for other stuff.</p>
  
  <p>I would like the cardview to be square.</p>
  
  <p>I set the CardView's height to "match_parent". But how do I set it's width to match it's height?</p>
  
  <p>Am I going to have to create a custom View and use OnMeasure(), or is there a simpler way?</p>
  
  <p>Here is my view's XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity"&gt;
  
      LinearLayout
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="4" &gt;
  &lt;!--        Other stuff goes here--&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"&gt;
  
          &lt;androidx.cardview.widget.CardView
              android:id="@+id/card_view"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_margin="5dp"
              android:clickable="true"
              android:foreground="?selectableItemBackground"
              app:cardBackgroundColor="#81C784"
              app:cardCornerRadius="12dp"
              app:cardElevation="3dp"
              app:contentPadding="4dp"&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/card_name"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:textColor="#000000"
                      android:textSize="15sp"
                      android:text="TEST"/&gt;
  
                  &lt;TextView
                      android:id="@+id/card_desc"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:textColor="#000000"
                      android:textSize="12sp"
                      android:text="123"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/card_image"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:adjustViewBounds="true"
                      android:padding="3dp"
                      android:scaleType="fitCenter"
                      android:src="@mipmap/ic_launcher"
                      /&gt;
              &lt;/LinearLayout&gt;
          &lt;/androidx.cardview.widget.CardView&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is a screenshot of what, roughly, I would like the cardview to look like:
  <a href="https://i.stack.imgur.com/GEKls.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GEKls.png" alt="enter image description here"></a></p>