I’m trying to set the FrameLayout‘s width and height based on a Bitmap, what I did was below
Bitmap theBitmap = BitmapFactory.decodeFile(theFileImage.toString());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(theBitmap.getWidth(), theBitmap.getHeight());
frame.setLayoutParams(lp);
image.setLayoutParams(lp);
image.setImageBitmap(theBitmap);
but I’m getting a ClassCastException.
What did I do wrong?
Edited:
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
For setting Layout params, you need to use the inner class LayoutParams of its parent.
For Example : If you are having a LinearLayout inside RelativeLayout and if you need to set the layout params of Linear Layout, you need to use the LayoutParams inner class of RelativeLayout. Else it will gives a ClassCastException.
So in your case, for setting the FrameLayout’s Layoutparams , you need to use its parent Layout’s Layout Params. Suppose if your layout is like :
Code :