What is the difference between match_parent and fill_parent?

后端 未结 17 1733
离开以前
离开以前 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:28

    FILL_PARENT is deprecated in API level 8 and MATCH_PARENTuse higherlevel API

    0 讨论(0)
  • 2020-11-22 08:28

    FILL_PARENT was renamed MATCH_PARENT in API Level 8 and higher which means that the view wants to be as big as its parent (minus padding) - Google

    0 讨论(0)
  • 2020-11-22 08:31

    fill_parent: The view should be as big as its parent.

    now this content fill_parent is deprecated and replaced by match_parent.

    0 讨论(0)
  • 2020-11-22 08:32

    1. 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.

    Also note that padding is applied to all sides,

    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    

    Now lets add a sub-view LinearLayout and sets its layout_width="match_parent" and layout_height="match_parent", the graphical view would display something like this,

    match_parent_example

    Code

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.code2care.android.togglebuttonexample.MainActivity" >
    
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="11dp"
    android:background="#FFFFEE"
    android:orientation="vertical" >
    

    2. fill_parent :

    This is same as match_parent, fill_parent was depreciated 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.

    0 讨论(0)
  • 2020-11-22 08:39

    match_parent and fill_parent are same property, used to define width or height of a view in full screen horizontally or vertically.

    These properties are used in android xml files like this.

     android:layout_width="match_parent"
     android:layout_height="fill_parent"
    

    or

     android:layout_width="fill_parent"
     android:layout_height="match_parent"
    

    fill_parent was used in previous versions, but now it has been deprecated and replaced by match_parent. I hope it'll help you.

    0 讨论(0)
提交回复
热议问题