I have a few buttons in my Android app. They each look kinda like this:
<Button
android:id="@+id/button_1"
android:drawableTop="@drawable/an_icon"
android:background="@drawable/a_background"
android:layout_width="size_dp"
android:layout_height="size_dp">
</Button>
Granted, I'm new to Android dev, but I can't figure out how to center the drawable in my button. I've tried the different drawableLocations, margins and padding for the button and its container, as well as drawablePadding, but I can't seem to get it done. Is there a way to center the drawable without abandoning Button for another View?
The easiest solution is to use ImageButton widget:
So you can have both (background & drawable) by using
ImageView
as below: (So No need to use Button)For
OnClick
ofImageView
:Try this: