Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align the image in image button

I want to place my image with in the allocated image button view. but it doesn't fixed with in that space and it looks odd ! ! is it possible to align the image with in allocated space for image button or i have to crop and set up ?

like image 569
Mohan Raj Avatar asked Jun 15 '13 04:06

Mohan Raj


People also ask

How do you fit a picture inside a button?

How to programatically resize and show them? Use a android:scaleType="fitCenter" to have Android scale the images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling. All of these attributes can be set in code on each ImageButton at runtime.

What is difference between Button and image button?

So fundamentally, a Button can have text and is clickable, whereas an ImageButton is a bit more flexible in how you set the image. It has methods from its ImageView base class like setImageURI which a Button does not.

What is image button control?

Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button , with the standard button background that changes color during different button states.

Which property should be called for image in ImageButton?

Setting Image Source In ImageButton Using Java class: We can also set the source image at run time programmatically in java class. For that we use setImageResource() function as shown in below example code.


1 Answers

Image in the ImageButton tag to be aligned to the left.

<ImageButton 
    android:id="@+id/sample"
    android:layout_gravity="left"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:scaleType="fitStart" 
    android:src="@drawable/sample" >
</ImageButton>
like image 171
Ganesh Rengarajan Avatar answered Oct 16 '22 10:10

Ganesh Rengarajan