I have set a Bitmap to an ImageView and then want to set wrap_content for both width and height.
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);
It is giving java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams
What is the problem in my code? How to solve?