title: Android Set wrap_content to ImageView by java code prob
body: <p>I have set a Bitmap to an ImageView and then want to set wrap_content for both width and height.</p>
  
  <pre><code>imgSubsegment = (ImageView) findViewById(R.id.subsegment);
  
  ViewGroup.LayoutParams imageViewParams = new ViewGroup.LayoutParams(
                  ViewGroup.LayoutParams.WRAP_CONTENT,
                  ViewGroup.LayoutParams.WRAP_CONTENT);
  
  ......................................
  
  imgSubsegmentSensor.setImageBitmap(bmpSubsegmentSensor);
  imgSubsegmentSensor.setLayoutParams(imageViewParams);
  </code></pre>
  
  <p>It is giving <code>java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams</code></p>
  
  <p>What is the problem in my code? How to solve?</p>