Home » Android » android – How to align the image source within the ImageButton?

android – How to align the image source within the ImageButton?

Posted by: admin June 15, 2020 Leave a comment

Questions:

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>

How to&Answers:

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.