For the More Curious: Margins vs Padding

In both GeoQuiz and CriminalIntent, you have given widgets 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 widgets. Given that a widget can only know about itself, margins must be the responsibility of the widget’s parent.

Padding, on the other hand, is not a layout parameter. The android:padding attribute tells the widget 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 10.34).

Figure 10.34  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 Nov 14 11:56 EST 2018"/>

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
18.216.190.167