Reputation: 121
In my Button I have this XML:
<Button
android:id="@+id/btnFiltrarResultados"
android:layout_width="18dp"
android:layout_height="17dp"
android:layout_above="@+id/searchView"
android:layout_alignParentEnd="true"
android:layout_marginBottom="-37dp"
android:layout_marginEnd="29dp"
android:background="@drawable/filtrar_explorar"
android:cropToPadding="true"
android:padding="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/txtExploreTitulo"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.01999998" />
But I can't seem to be able to add padding to it. I've tried using cropToPadding
or using android:src
but nothing seems to help...
Upvotes: 0
Views: 1883
Reputation: 583
Well it's not a way to add image in button, as you did in your xml fileandroid:background="@drawable/filtrar_explorar"
. because by default background image try to scale as much as possible and ignore padding.So the good practice is use ImageButton
with android:src="@drawable/use_your_image"
and add android:scaletype="fitCenter"
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/use_your_image"
android:scaleType="fitCenter"
android:padding="10dp"
/>
Upvotes: 1
Reputation:
You have
android:layout_width="18dp"
android:layout_height="17dp"
and expect padding 20dp
Upvotes: 3