Friday 13 October 2017

android - What's the difference between fill_parent and wrap_content?

itemprop="text">

In Android, when layout out widgets,
what's the difference between fill_parent
(match_parent in API Level 8 and higher) and
wrap_content?



Is there
any documentation where you can point to? I'm interested in understanding it very
well.



itemprop="text">
class="normal">Answer



Either
attribute can be applied to View's (visual control) horizontal or vertical size. It's
used to set a View or Layouts size based on either it's contents or the size of it's
parent layout rather than explicitly specifying a
dimension.



fill_parent
(deprecated and renamed MATCH_PARENT in API Level 8 and
higher)



Setting the layout of a widget to
fill_parent will force it to expand to take up as much space as is available within the
layout element it's been placed in. It's roughly equivalent of setting the dockstyle of
a Windows Form Control to Fill.



Setting a top level layout or control to
fill_parent will force it to take up the whole
screen.



wrap_content




Setting
a View's size to wrap_content will force it to expand only far enough to contain the
values (or child controls) it contains. For controls -- like text boxes (TextView) or
images (ImageView) -- this will wrap the text or image being shown. For layout elements
it will resize the layout to fit the controls / layouts added as its
children.



It's roughly the equivalent of setting
a Windows Form Control's Autosize property to
True.



Online
Documentation



There's some
details in the Android code documentation href="http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html"
rel="noreferrer">here.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...