Android Question -2 for auto adjust size depending on a view's content?


Licensed User
In this example labels are created at runtime like


which causes the label to adjusts it's height automatically depending on the textsize.

Did I miss that? If yes: Why? :) (I can't find any documentation even in the www)


Licensed User
I can't find any documentation even in the www

Specifies the basic height of the view. This is a required attribute for any view inside of a containing layout manager. Its value may be a dimension (such as "12dip") for a constant height or one of the special constants.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

May be one of the following constant values.

fill_parent-1 The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.
match_parent-1 The view should be as big as its parent (minus padding). Introduced in API Level 8.
wrap_content-2 The view should be only big enough to enclose its content (plus padding).
Upvote 0


Licensed User
If I remember correctly, when using this querying the height or width will return -2. So good for easy layout, but not so good if you want to measure it later.
Upvote 0