Difference Between a Clickable Imageview and Imagebutton

Difference between a clickable ImageView and ImageButton

There's no differences, except default style. ImageButton has a non-null background by default.

EDIT: Also, ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it's always inflated as focusable.

Here's ImageButton's default style:

 <style name="Widget.ImageButton">
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:scaleType">center</item>
<item name="android:background">@android:drawable/btn_default</item>
</style>

Difference between Button with image, ImageButton, and clickable ImageView?

This probably only covers part of the differences, it would be helpful to actually look at the Android Source tree to see exactly what's going on.

ImageButtons has push states, where as a clickable image does not.
You also can't call setText for ImageButton, you can with a regular button.

They all derive from view, but looking at the following extends chain may help a little.

java.lang.Object
↳ android.view.View
↳ android.widget.ImageView
↳ android.widget.ImageButton

versus

java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.Button

When to use ImageButton rather than ImageView?

This question was answered quite thoroughly here: Difference between a clickable ImageView and ImageButton

To sum it up: There's no differences, except default style. ImageButton has a non-null background by default.

Button or clickable imageview?

The main difference between them is that a button has different push states(pressed, selected, focussed etc.) that you can use, while a clickable ImageView doesn't.

Difference in appearance of Button and ImageButton

Button has default elevation (actually, it has a StateListAnimator that provides elevation when the button is enabled) under the Material theme, whereas ImageButton does not.

Difference between image button and button

Button extends TextView, allowing you to create clickable text with a background image.
http://developer.android.com/reference/android/widget/TextView.html

ImageButton extends Image view, which has more methods relevant to the manipulation of images.
http://developer.android.com/reference/android/widget/ImageView.html

Clickable area bigger than imageButton

Just increase the padding and size of your image

<ImageButton
android:id="@+id/skipButton"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@null"
android:onClick="onSkipButtonPressed"
android:padding="10dp"
android:scaleType="fitCenter"
android:scaleX="0.5"
android:scaleY="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/hintTextView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.989"
app:srcCompat="@drawable/skip_button_selector/>

also you can use paddingEnd and paddingBottom attributes it will not change position of your image but increase the area

<ImageButton
android:id="@+id/skipButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@null"
android:onClick="onSkipButtonPressed"
android:paddingEnd="10dp"
android:paddingBottom="10dp"
android:scaleType="fitCenter"
android:scaleX="0.5"
android:scaleY="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/hintTextView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.989"
app:srcCompat="@drawable/skip_button_selector/>


Related Topics



Leave a reply



Submit