Reputation: 798
I read often something like this:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
What exactly LayoutParams do? I've read the Documentary but I wasn't smarter after reading!
Hope someone can explain me what LayoutParams do or pass!
Kind Regards!
Upvotes: 2
Views: 2181
Reputation: 689
Basically when you set an xml with 'match_parent' or anything like layout_something the android inflator will set the layout param for the child with the appropriate Layout params with the type matching the parent control, you could also do this in code and if you forget or set the wrong type you will get an exception in runtime. the parent control needs this information to layout the child control correctly and to his liking.
Please see the following: Android Developer site - Layout Params
I think this picture says it all
Upvotes: 1
Reputation: 11
LayoutParams is use for the dynamically change the layout width and height. and also use the create custom view without the xml by using the directly by use of the LayoutParams for Relative or Linear type layout.
Upvotes: 1
Reputation: 7082
LayoutParams
are the Java Object representation of all the params you give to your View
in the .xml layout file, like layout_width
, layout_height
and so on. Getting this object from a View
allows you to look up those params on runtime, but also to change them in your Java code, when you need to move the View
, change it's size etc.
Upvotes: 3
Reputation: 3873
LayoutParams are used by views to tell their parents how they want to be laid out.
The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:
FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding) WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content.
That's all folks.
Upvotes: 1