Topic : Android Layout Params: FILL_PARENT: | MATCH_PARENT: | WRAP_CONTENT:

Layout Params:

Layout Params are used by views to tell their parents how they want to be laid out. The basic Layout Params just describes how big the view wants to be for both width and height. For each dimension, it can specify one of -




WRAP_CONTENT:

WRAP_CONTENT will display the component big enough to just enclose it Content only. For example: If We Declare button name as "button" and set its height & width as wrap_content then it will creates button containing "button" name size and does not occupy more then its content area.


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/btnButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="My Button"
        android:background="#008080" />
</RelativeLayout>

Wrap-content: infobrother

FILL_PARENT:

FILL_PARENT will display the component as big as its parent, and will fill in the remaining spaces. For Example, If our Parent tag has 100dp set into width and 100dp into height then it will cover our whole parent area. Parent is our first main defining Layout tag.


fill_parent Width:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/btnButton1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="My Button"
        android:background="#008080" />
</RelativeLayout>

Fill-parent width: infobrother

fill_parent Height:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/btnButton1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="My Button"
        android:background="#008080" />
</RelativeLayout>

Fill-parent Height: infobrother

fill_parent Width & Height:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/btnButton1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="My Button"
        android:background="#008080" />
</RelativeLayout>

Fill-parent Width and Height: infobrother

MATCH_PARENT:

MATCH_PARENT is same as FILL_PARENT which display the component as big as its parent.



NOTE: We can Specifying an Exact width and height, but it's not recommended, due to Android Variety of Devices screen size. We just do not know what size of Android device is running our application.


















I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother





WRITE FOR INFOBROTHER

Advertising






Advertisement