Question

just want to know what happens when I set new layout params to a new instance of an ImageView and then add it on an empty layout. It seems like doing it reset the parent layout hosting the new ImageView and also reset position and size of every sibling ImageView.

So what happens? Parent layout takes the layoutparams of the child?

thanks

Was it helpful?

Solution

Layout params have direct affect to views which use that params. But that also affects other views under same parent. Think about width, height and weight attrs of linear layout params. For example, if you set a layout params which has a weight attr defined, this will all change the visual of your parent.

From the doc:

LayoutParams are used by views to tell their parents how they want to be laid out.

Note: A parent is a view group, a container for child views. There are some types of view groups, ie LinearLayout, RelativeLayout etc(subclasses of ViewGroup can be googled), and they have specific layout behaviours and LayoutParams. While adding views to view groups layout params are used (both on xml and programmatically) for setting position, width, height inside that view group(container).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top