I have Buttons that look like the top image for the landscape orientation:
screenshot http://i46.tinypic.com/33zb9dj.jpg
I want it to look like the bottom image.
Here's my .xml code for these buttons.
<TableRow
android:id="@+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:weightSum="1.0" >
<ImageButton
android:id="@+id/appHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:background="@null"
android:contentDescription="Home"
android:cropToPadding="true"
android:scaleType="fitEnd"
android:src="@drawable/home_bar" />
<ImageButton
android:id="@+id/menuHome"
android:layout_weight="0"
android:background="@null"
android:contentDescription="Menu"
android:cropToPadding="true"
android:scaleType="center"
android:src="@drawable/menu_bar" />
<ImageButton
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:background="@null"
android:contentDescription="Back"
android:cropToPadding="true"
android:scaleType="fitStart"
android:src="@drawable/back_bar" />
</TableRow>
An easier alternative to creating your own 9 patch image to remove the margin is to set the background to null.
For example, add the following to res/styles.xml:
You should now find that all ImageButtons have zero margin, regardless of whether defined in XML or created programatically.
//remove the
android:weightSum
use width asmatch_parent
//give
android:layout_weight="1"
for all imageButton//use
android:scaleType="fitXY"
for allUse negative padding on the
ImageButton
in your xml to shrink the padding used.Note the above is just an example... you'll need to mess with the numbers to adjust for your specific case to make things look correct.
I ended up fixing this by switching my TableLayout to a LinearLayout. Here's my code unless anyone else comes across this problem:
You cannot do that with the default buttons, the buttons 9 patches have a padding in them (both, holo and the pre holo buttons). You can see that here.
If you want buttons without padding then you'll have to modify the 9 patches and create your own theme:
and your imageButtonStyle: