Using wrap_content and match_parent
In order to cater to the need of a variety of android devices available in the market, the application needs to be compatible to different screen sizes. For example, a layout should adapt to different screen sizes, and the corresponding views should also resize accordingly. To ensure that we make use of wrap_content
and match_parent
for width and height of view components refer to the following:
wrap_content
: It ensures that the width and height of the view is set to the minimum size required to fit the contentmatch_parent
: Before API level 8, it was known asfill_parent
and it ensures the component expands to match the size of its parent view
Therefore, use of these attributes affirms our views to use the space required and expands to fill the available space. We have made use of these in the DistanceConverter application for components in layout file. Following is a small code snippet from activity_main.xml
, our previous application to demonstrate its...