title: Cardview is not resizing itself when inner element is removed/hidden/resized
body: <p>I have created cardview in following way. All fields get populated on response of a webservice. But cardview is not getting resized as per populated data. </p>
  
  <p>For textview, it leaves some space below the data.</p>
  
  <pre><code>&lt;android.support.v7.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/cv2"
          android:elevation="20dp"
          android:layout_marginTop="1dp"
          app:cardCornerRadius="0dp"
          &gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:padding="16dp"
              android:id="@+id/Lin2"
              android:layout_marginTop="30dp"
              android:orientation="vertical"
              android:animateLayoutChanges="true"
              android:visibility="visible"
              android:weightSum="100"&gt;
  
              &lt;AutoCompleteTextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:hint="@string/prompt_username"
                  android:id="@+id/usernameTextView"
                  android:layout_marginTop="10dp"
                  android:layout_weight="20"
                  android:minHeight="50dp"
                  android:minLines="1" /&gt;
              &lt;AutoCompleteTextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:password="true"
                  android:hint="Password"
                  android:id="@+id/passwordTextView"
                  android:layout_weight="20"
                  android:minHeight="50dp"
                  android:minLines="1" /&gt;
  
              &lt;Button
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="Update"
                  android:id="@+id/updateBtn"
                  android:background="@drawable/button_border"
                  android:textColor="#005AB4"
                  android:layout_weight="20"/&gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="40"
                  android:id="@+id/credsNote"
                  android:textSize="14sp"
                  android:text=""
                  android:layout_marginTop="10dp"
                  android:layout_marginBottom="10dp"
                  android:maxLines="7"
                  android:soundEffectsEnabled="true" /&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:padding="16dp"
              android:orientation="horizontal"
              android:id="@+id/cvLin2"
              android:weightSum="100"
              &gt;
  
              &lt;ImageView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/cv2Btn"
                  android:src="@drawable/cancel"
                  android:layout_weight="20"
                  /&gt;
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/cv2Title"
                  android:textSize="18sp"
                  android:layout_gravity="center"
                  android:layout_marginLeft="20dp"
                  android:text="Credentials"
                  android:layout_weight="80"
                  /&gt;
  
              &lt;ImageView
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:id="@+id/cv2ImgHazard"
                  android:src="@drawable/hazard_yellow"
                  android:layout_weight="20"
                  /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>Java code to populate the data </p>
  
  <pre><code>                        usernameTxt = (AutoCompleteTextView)findViewById(R.id.usernameTextView);
                          passwordTxt = (AutoCompleteTextView)findViewById(R.id.passwordTextView);
                          usernameTxt.setText(username);
                          passwordTxt.setText(password);
                          String message = "All set here!";
                          credsNote = (TextView)findViewById(R.id.credsNote);
                          credsNote.setText(message);
                          credsNote.setMinLines((1));
                          credsNote.setMaxLines((1));
                          int height_in_pixels = credsNote.getLineCount() * credsNote.getLineHeight(); //approx height text
                          credsNote.setHeight(height_in_pixels);
                          Drawable res = getResources().getDrawable(R.drawable.tick);
                          credStat = (ImageView)findViewById(R.id.cv2ImgHazard);
                          credStat.setImageDrawable(res);
  </code></pre>
  
  <p>Please check images below to get more idea about the problem.
  How to resolve this issue?</p>
  
  <p><a href="https://i.stack.imgur.com/DhKp3.jpg" rel="nofollow noreferrer">Head part issue</a></p>
  
  <p><a href="https://i.stack.imgur.com/m6vNQ.jpg" rel="nofollow noreferrer">Bottom space issue</a></p>