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 ?
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With