Making Uniform Buttons

Before creating any XML drawables, modify res/layout/list_item_sound.xml to prep your buttons for the changes to come.

Listing 22.1  Spacing the buttons out (res/layout/list_item_sound.xml)

<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
                name="viewModel"
                type="com.bignerdranch.android.beatbox.SoundViewModel"/>
    </data> 
    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">
        <Button
                android:layout_width="match_parent"
                android:layout_height="120dp"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center" android:onClick="@{() -> viewModel.onButtonClicked()}" ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.