Skip to content Skip to sidebar Skip to footer

Android Button Shape Drawable Margin

Im styling a button using a shape drawable, this causes the button to over expand a little or lose it's margin so it doesnt align well with the other buttons. any idea why: This i

Solution 1:

Look at the below figure.. The default button is 9 patch image so there is always extra space after the button, This is the capture of your button. So when you set the background resource the empty space is filled by the image. So Better use ImageView instead. It will work perfectly with the imageview. Although there might be solutions like padding but they will fail in some situtation. You can implement the functionality with the ImageView. I hope this will help you.

Default Button

Solution 2:

Seems like each button has some dp of padding or layout marging.

Try to set

android:padding=0

If that does not work

android:layout_margin=0

This will eliminate the margin from the default buttons, if you want to solve the other way, add margin to the custom button

Solution 3:

That probably is because the canvas of the other drawables might have a padding.

Check the canvas padding[not the one you set in xml but the one that designers set in the image itself] and match it with your new drawable and see if they are the same. They should be the same.

Solution 4:

Try with my below layout i have done some relevant changes:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/LinearLayout1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><TableLayoutandroid:layout_width="fill_parent"android:layout_height="0dip"android:layout_weight="1"android:stretchColumns="*"android:weightSum="2" ><TableRowandroid:id="@+id/tableRowMem"android:weightSum="1" ><Buttonandroid:id="@+id/buttonA"android:layout_width="0dip"android:layout_height="fill_parent"android:layout_weight="0.5"android:text="A"/><Buttonandroid:id="@+id/buttonB"android:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="0.5"android:text="B" /></TableRow><TableRowandroid:id="@+id/tableRow1"android:weightSum="1" ><Buttonandroid:id="@+id/buttonC"android:layout_width="0dp"android:layout_weight=".5"android:layout_height="fill_parent"android:text="C" /><Buttonandroid:id="@+id/buttonD"android:layout_width="0dp"android:layout_weight="0.5"android:layout_height="fill_parent"android:background="@drawable/buttonred"android:text="D" /></TableRow></TableLayout></LinearLayout>

Solution 5:

Add padding to button.

android:padding="0dp"

Post a Comment for "Android Button Shape Drawable Margin"