For the More Curious: Margins vs Padding

In both GeoQuiz and CriminalIntent, you have given views margin and padding attributes. Beginning developers sometimes get confused about these two. Now that you understand what a layout parameter is, the difference is easier to explain.

Margin attributes are layout parameters. They determine the distance between views. Because a view can only know about itself, margins must be the responsibility of the view’s parent.

Padding, on the other hand, is not a layout parameter. The android:padding attribute tells a view how much bigger than its contents it should draw itself. For example, say you wanted the date button to be spectacularly large without changing its text size (Figure 11.36).

Figure 11.36  I like big buttons and I cannot lie…

I like big buttons and I cannot lie…

You could add the following attribute to the Button:

    <Button
        android:id="@+id/crime_date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="80dp"
        tools:text="Wed May 11 11:56 EST 2022"/>

Alas, you should probably remove this attribute before continuing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset