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

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

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.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}