The difference between Match_parent and fill_parent in Android layouts

Source: Internet
Author: User

Today when doing a new function of the project, looking for resources from the Internet, found that the match_parent that appeared in android2.2 was not clear. In the past there was only fill_parent and wrap_content so match_parent what is the type?


After some research, from the beginning of Android 2.2 fill_parent renamed to Match_parent, from the API level of 8 we can directly use Match_parent to replace the fill_parent, their definition of the essence is the same-1. Just to change the alias, perhaps to be more accurate, for example, finally in the SDK is defined as:


Fill_parent-1 The view should is as big as its parent (minus padding). This constant are deprecated starting from API Level 8 and are replaced by match_parent.
Match_parent-1 The view should is as big as its parent (minus padding). Introduced in API level 8.
Wrap_content-2 The view should is only a big enough to enclose its content (plus padding).


From the beginning of Android 2.2 fill_parent renamed to Match_parent, from the API level 8 can be directly used match_parent to replace the fill_parent, only 2.2 later version number fill_parent still be able to use , they all have the same meaning, filling the entire parent form


Three properties are used to fit the horizontal or vertical size of the view, and a layout based on the contents or dimensions of the view is more convenient than specifying the view range precisely.


1) fill_parent


Setting the layout of a component to fill_parent will force the component to expand to fill as much space as possible within the layout unit.

This is roughly the same as the DockStyle property of Windows controls. Setting a top layout or control for Fill_parent will force it to fill the entire screen.


2) wrap_content


Setting the size of a view to Wrap_content will force the view to expand to show all content. Take the TextView and ImageView controls as an example. Set to Wrap_content to display the text and images inside it completely. Layout elements will change size based on content.

Setting the size of a view to Wrap_content is roughly equivalent to setting the AutoSize property of Windows controls to true.


3) Match_parent
Android2.2 in Match_parent and fill_parent is a meaning. Two references mean the same thing. Match_parent more appropriate. So from 2.2 to two words can be used.

So assuming that you consider the use of the lower version, you need to use fill_parent.

The difference between Match_parent and fill_parent in Android layouts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.