How to differentiate Android wrap_content from fill_parent

Source: Internet
Author: User

How to differentiate Android wrap_content from fill_parent

In Android, do I always confuse "wrap_content" or "fill_parent" component attributes "layout_width" and "layout_height?

Let's take a look at the following definition:

Wrap_content-the component only needs to display content large enough to enclose it.
Fill_parent-fill in the remaining space if the component is to be displayed as large. (Renamed match_parent at API Level 8)
Let's take a look at the following demo:

1. Wrap_content
A button component that sets "wrap_content" in the width and height attributes. It tells Android that the display button is large enough to put its content "button ABC" only.



Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">

 

Image.png

2. Fill_parent-Width
If you change "layout_width" "fill_parent", the button width will fill in the remaining space, because the height of the button "as big as relative layout" is still enough to put its content.



Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">

 

Image.png

3. fill_parent-height
If you change "layout_height" "fill_parent", the height of the button will fill the remaining space, because the width of the button "as big as relative layout" is still enough to put its content.



Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">

 

Image.png

4. Fill_parent-width and height
The "layout_width" and "layout_height" "fill_parent" buttons are displayed as large as the screen of the entire device. They only fill up the entire screen space.



Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">

 

Image.png

Original blog address: http://www.apkbus.com/blog-919651-76525.html
In fact, you can specify an exact width and height, but this is not recommended because of the various screen sizes of Android devices. You just don't know what size Android devices are running on your fantasy app.

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.