• support@answerspoint.com

What is the difference between match_parent and fill_parent?

488

I'm a little confused about two XML properties: match_parent and fill_parent. It seems that both are the same. Is there any difference between them?

1Answer


0

These are called as Layout Parameters. They are used by sub-views to tell the parent view how they want to be laid on the Activity screen i.e we can set the Horizontal and Vertical size of a view using Layout Parameters

To specify how big a view must be we use android:layout_width and android:layout_height attributes. 

The values of these attributes can either one of fill_parent, match_parent or wrap_content

match_parent

 fill_parent :


This is same as match_parent, fill_parent was Dipricated in API level 8. So if you are using API level 8 or above you must avoid using fill_parent 

Lets follow the same steps as we did for match_parent, just instead use fill_parent everywhere. 

You would see that there is no difference in behaviour in both fill_parent and match parent. 

    • When you set layout width and height as match_parent, it will occupy the complete area that the parent view has, i.e. it will be as big as the parent. 

      Note : If parent is applied a padding then that space would not be included. 

      When we create a layout.xml by default we have RelativeLayout as default parent View with android:layout_width="match_parent" and android:layout_height="match_parent" i.e it occupies the complete width and height of the mobile screen. 
  • answered 8 months ago
  • B Butts

Your Answer

    Facebook Share        
       
  • asked 3 years ago
  • viewed 488 times
  • active 3 years ago

Hot Questions