title: What kind of LayoutParams should I use?
body: <p>Problem description:</p>
  
  <p>I have a customized ImageView:</p>
  
  <pre><code>public class TestImageView extends ImageView {
  ...
      public void onImageLoaded(Bitmap bitmap) {
          int width = DeviceInfo.getScreenWidth();
          int height = width * (float) bitmap.getHeight() / (float) bitmap.getWidth();
          ViewGroup.MarginLayoutParams layoutParams =
                  new ViewGroup.MarginLayoutParams(width, height);
          this.setLayoutParams(layoutParams);
      }
  }
  </code></pre>
  
  <p>Then I received this error:</p>
  
  <pre><code>java.lang.ClassCastException: android.view.ViewGroup$MarginLayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
  </code></pre>
  
  <p>In my project I did make an instance of TestImageView the child of a FrameLayout. So if I change ViewGroup.MarginLayoutParams to FrameLayout.LayoutParams it will work. But this customized ImageView could be inside other kind of layouts like LinearLayout. I don't think I should restrict it to FrameLayout.layoutParams here.</p>
  
  <p>So what should I do here? More generally, why Android make different LayoutParams? The LayoutParams classes seems identical? I don't see a necessity.</p>