Skip to content

Android wrap_content and fill_parent

March 2, 2014

The fill_parent and wrap_content are opposite of each other.

1. wrap_content is used for those components that just need to occupy enough space to display their content. If android:layout_width and android:layout_height for the given component are set to wrap_content its widths and height both do not take extra space more than required by their content.

Example:

<Button
android:id=”@+id/myButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”My Content”/>

In the example above the button will have enough width and height to hold the content “My Content”.

2. fill_parent is used where the component is needed to be displayed to as big as its parent. The component may fill its parent length wise, width wise or both as required. In the example below the button will be wide enough as its parent component, and its height will be long enough just to hold its contents, “My Content”.

Example:
<Button
android:id=”@+id/myButton”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”My Content”/>

Further reading:

http://www.mkyong.com/android/android-wrap_content-and-fill_parent-example/

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: