How to align the image source within the ImageButton?

Mel picture Mel · Jul 14, 2011 · Viewed 8.4k times · Source

I have an image button that I want to take to entire width of the device. The image src I am using is not as long as the button. The default seems to be to align it to the cener of the button. Instead I would like to align it to the left. I have tried using layout gravity but with no response.

Here is the code..

<LinearLayout 
   android:id = "@+id/llRoot"
   android:orientation="vertical"
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent"
   android:layout_gravity="left"  >

    <ImageButton 
    android:id="@+id/ibSend"
    android:layout_gravity="left"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:src="@drawable/send" >
     </ImageButton>

Answer

Khawar picture Khawar · Jul 14, 2011

Well, I think you want your image in ImageButton to be alligned to the Left? Then add this to your ImageButton attributes:

android:scaleType="fitStart"

and here it goes, your image is aligned at left of the ImageButton.