What is the difference between match_parent and fill_parent?

后端 未结 17 1895
离开以前
离开以前 2020-11-22 07:37

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 the

17条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 08:23

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

    
    
        
    
    
    

    Hare parent is red and child is green. Child occupy all area. Because it's width and height are match_parent.

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

    
    
        
    
    
    

    So TextView hight = 300dp(parent hight) - (20(paddingTop)+10(paddingBottom)) = (300 - 30) dp = 270 dp

    fill_parent Vs match_parent

    fill_parent is previous name of match_parent

    For API Level 8 and higher fill_parent renamed as match_parent and fill_parent is deprecated now.

    So fill_parent and match_parent are same.

    API Documentation for fill_parent

    The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by {@code match_parent}.

提交回复
热议问题