Difference between view fill and margin

Keywords: Android xml encoding

What is the difference between the margin and fill of the view?

#1st floor

Filling is the space within the boundary between the boundary and the actual image or cell contents.A boundary is the space outside the boundary between the boundary and other elements next to the object.

#2nd floor

Sometimes you can achieve the same result by using only padding or margins.Example:

Say View X contains View Y (also known as View Y inside View X).

- View Y with margin = 30 or view X with fill = 30 will get the same result: view Y has an offset of 30.

#3rd floor

To help me remember what padding means, I think of a large coat with a lot of thick cotton padding on it.I'm in my coat, but I'm with my cotton coat.We are a unit.

But to remember the balance, I thought,'Hey, give me some!'This is the gap between me and you.Don't enter my comfort zone - my edge.

For clarity, this is a picture of the fill and margin of TextView:

The xml layout of the diagram above

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#c5e1b0"
        android:textColor="#000000"
        android:text="TextView margin only"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#f6c0c0"
        android:textColor="#000000"
        android:text="TextView margin only"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#c5e1b0"
        android:padding="10dp"
        android:textColor="#000000"
        android:text="TextView padding only"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#f6c0c0"
        android:padding="10dp"
        android:textColor="#000000"
        android:text="TextView padding only"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#c5e1b0"
        android:textColor="#000000"
        android:padding="10dp"
        android:text="TextView padding and margin"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#f6c0c0"
        android:textColor="#000000"
        android:padding="10dp"
        android:text="TextView padding and margin"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#c5e1b0"
        android:textColor="#000000"
        android:text="TextView no padding no margin"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#f6c0c0"
        android:textColor="#000000"
        android:text="TextView no padding no margin"
        android:textSize="20sp" />

</LinearLayout>

Of

#4th floor

Suppose you have a button in the view, and the size of the view is 200 x 200, the size of the button is 50 x 50, and the button title is HT.The difference between margin and padding is that you can set the margin of a button in the view, for example, from 20 on the left, from 20 on the top, and padding adjusts the position of the button or text in the text view., the fill value starts at 20 from the left, so it adjusts the position of the text.

#5th floor

The following image will show you the padding and margins-

Posted by jlive on Thu, 09 Jan 2020 18:54:14 -0800