How do you setLayoutParams() for an ImageView?


I want to set the LayoutParams for an ImageView but cant seem to find out the proper way to do it.

I can only find documentation in the API for the various ViewGroups, but not an ImageView. Yet the ImageView seems to have this functionality.

This code doesn't work...

myImageView.setLayoutParams(new ImageView.LayoutParams(30,30));

How do I do it?

4/8/2013 12:02:31 PM

You need to set the LayoutParams of the ViewGroup the ImageView is sitting in. For example if your ImageView is inside a LinearLayout, then you create a

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);

This is because it's the parent of the View that needs to know what size to allocate to the View.

6/3/2010 12:18:51 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow