Control the size deterministically with specific measurements. For example:
<Button
android:id="@+id/button3"
android:layout_weight="1"
android:layout_height="50dp"
android:layout_width="50dp"
android:background="@drawable/home_icon"
android:text="Settings"
/>
For even more control over the button's design use a container such as a RelativeLayout to hold the image and the text. Then assign an onClickListener to the container to turn it into a clickable button. Here's an example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/snazzy_button_with_image_above_text"
android:layout_width="wrap_content"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginLeft="1dp"
android:background="@color/SkyBlue"
android:paddingBottom="2dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="1dp" >
<ImageView
android:id="@+id/your_image"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/white"
android:contentDescription="image inside button"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/your_text"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/your_image"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp"
android:background="@color/translucent_black"
android:gravity="bottom|center_horizontal"
android:paddingTop="0dp"
android:text="Your Button Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/white"
android:textSize="10sp" />
</RelativeLayout>
In the code assign the onClickListener as such:
yourButton = (RelativeLayout) findViewById(R.id.snazzy_button_with_image_above_text);
yourButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View clickedButton) {
//button click action here
}