I needed to create a dynamic gallery yesterday. I could easily create an ImageView and add it to a container. But it was hard to set layout parameters to the image. I needed it to position it correctly. Most important need was to set its width as MATCH_PARENT. It can be done by setting up a proper LayoutParams object.