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

KMatle

Expert
Licensed User
Longtime User
In this example https://www.b4x.com/android/forum/threads/sms-baloon-labels.63953/ labels are created at runtime like

B4X:
Activity.AddView(MyLabel,0,0,100%x,-2)

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)
 

DonManfred

Expert
Licensed User
Longtime User
I can't find any documentation even in the www
https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

android:layout_height
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.

ConstantValueDescription
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

stevel05

Expert
Licensed User
Longtime 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
Top