Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Android Tips: MATCH_PARENT vs. FILL_PARENT

DZone's Guide to

Android Tips: MATCH_PARENT vs. FILL_PARENT

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

The mechanics of UI creation in Android development are not always the most intuitive. For that reason, Huyen Tue Dao at randomlytyping.org has written a set of tips on when to use Android's MATCH_PARENT and when to use FILL_PARENT. The short version looks like this:

  • When to use MATCH_PARENT: Always
  • When to use FILL_PARENT: Never

Basically, Dao argues that FILL_PARENT is a clunkier version of MATCH_PARENT used for the same purposes, but with more room for confusion, because FILL_PARENT doesn't actually do what its name implies. On top of that, FILL_PARENT is deprecated, so at some point it will no longer be supported. According to Dao, the reason both exist is a kind of ineffective attempt at clearing up developer confusing:

The Android team found that developers were misinterpreting FILL_PARENT to mean that a View would fill the remaining space left in its parent. In fact, by specifying FILL_PARENT, the View is requesting to be as big as its parent. Thus, (as explained by Romain Guy himself in this video at around 10:56) the constant was renamed MATCH_PARENT to clarify its use.

If you're not persuaded, Dao gives a couple of examples complete with XML layouts and device display images to illustrate her argument. Take a look at the full article for a more complete look at the difference between FILL_PARENT and MATCH_PARENT.

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
java ,mobile ,xml ,android ,ui ,tips and tricks ,tools & methods

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}