FILL_PARENT (renamed MATCH_PARENT starting Android API Level 8), is a constant describing that a view would like to be as big as its parent (minus any padding).
FILL_PARENT
(renamed MATCH_PARENT
starting Android API Level 8), is a constant describing that a view would like to be as big as its parent (minus padding). It can be used for both width and height. It is the opposite of WRAP_CONTENT
, which indicates that the view wants to be just big enough to enclose its content (plus padding).
Both constants are part of the ViewGroup.LayoutParams
class, from which all other LayoutParams
derive, and aid in ensuring that Android applications can display properly across a variety of device screen sizes and densities. The equivalents in XML share the same names, but all lowercase.
The sample below describes a LinearLayout
that vertically stacks a TextView
and Button
. The LinearLayout
requests to be sized as big as its parent by means of android:layout_width="match_parent"
and android:layout_height="match_parent"
. The two child views, however, are requested to limit their width and height to their contents using the wrap_content
values.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>