content: package com.an.dagger.ui.custom;
  
  import android.content.Context;
  import android.support.design.card.MaterialCardView;
  import android.util.AttributeSet;
  import android.view.ViewGroup;
  
  public class AspectRatioCardView extends MaterialCardView {
  
      private float ratio = 1.4f;
  
      public AspectRatioCardView(Context context) {
          this(context, null);
      }
  
      public AspectRatioCardView(Context context, AttributeSet attrs) {
          this(context, attrs, 0);
      }
  
      public AspectRatioCardView(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
      }
  
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          if (ratio > 0) {
              int ratioHeight = (int) (getMeasuredWidth() * ratio);
              setMeasuredDimension(getMeasuredWidth(), ratioHeight);
              ViewGroup.LayoutParams lp = getLayoutParams();
              lp.height = ratioHeight;
              setLayoutParams(lp);
          }
      }
  }