Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Layout - set spacing between Image Buttons

I have four buttons on top of a bar (background image) . What I'm trying to do is increase the spacing between the buttons (so they are spread out across the bar) and set the gravity to center_horozontal . I tries paddingLeft and paddingRight on ImageButtons (okcancelbar_button_home) themselves but it doesn't seem to do anything. I'm thinking maybe the Image Buttons parent is the key but I don't know what to set there. Here is my layout :

                        ///////// main .xml //////////////////

                <merge
                    xmlns:android="http://schemas.android.com/apk/res/android">


                    <com.onesix.test.OkCancelBar
                        android:layout_width="fill_parent" 
                        android:layout_height="60dip" 
                        android:layout_gravity="top"

                        android:paddingTop="0dip"
                        android:gravity="center_horizontal"

                        android:background="@drawable/header_bkgrnd"
                    />

                    <!--"#AA000000"-->
                </merge>




                ////////// okCancelBar ////////////////


                <merge xmlns:android="http://schemas.android.com/apk/res/android">
                    <include
                        layout="@layout/okcancelbar_button_home"
                        android:id="@+id/okcancelbar_home" 
                        android:layout_height="90dip" />

                    <include
                        layout="@layout/okcancelbar_button_lists"
                        android:id="@+id/okcancelbar_lists" 
                        android:layout_height="90dip"
                        />

                      <include
                        layout="@layout/okcancelbar_button_calendar"
                        android:id="@+id/okcancelbar_calendar" 
                        android:layout_height="90dip"
                        />

                     <include
                        layout="@layout/okcancelbar_button_search"
                        android:id="@+id/okcancelbar_search" 
                        android:layout_height="90dip"
                        />
                </merge>



                ////////////// okcancelbar_button_home ////////////////
                <?xml version="1.0" encoding="utf-8"?>
                <ImageButton 
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/but_home"
                    android:layout_width="75dip"
                    android:layout_height="60dip"
                    android:layout_alignParentBottom="true"
                    android:background="@android:color/transparent"
                    android:src="@drawable/button_menu_states_home"
                    android:paddingLeft="7dip"
                    android:paddingRight="7dip"
                    />



                ////////////button_menu_states_home/////////

                <?xml version="1.0" encoding="utf-8"?>
                 <selector xmlns:android="http://schemas.android.com/apk/res/android">
                     <item android:state_pressed="true"
                           android:drawable="@drawable/menu_button_home1_over" /> <!-- pressed -->
                     <item android:state_focused="true"
                           android:drawable="@drawable/menu_button_home1_over" /> <!-- focused -->
                     <item android:drawable="@drawable/menu_button_home1" /> <!-- default -->
                 </selector>
like image 506
Mike6679 Avatar asked Dec 01 '22 03:12

Mike6679


1 Answers

Changing the padding on a button will increase the size of the actual button. You can think of it as changing the padding for the button's text, not the button itself.

To change the spacing between the buttons you can use the layout_margin attributes (e.g. android:layout_marginLeft=...).

like image 63
Dillon Kearns Avatar answered Dec 05 '22 00:12

Dillon Kearns