Home > Blockchain >  Why ImageButton and Button have different heights for the same size?
Why ImageButton and Button have different heights for the same size?

Time:06-22

The problem is the following. I have an ImageButton and a Button, they have the same height and width. But the ImageButton is stretched to cover the entire area, but the Button is not. I need the Button to also fill the area completely in height.

Screenshots and code:

ImageButton and Button

<ImageButton
        android:id="@ id/backspaceImageBtn"
        android:layout_width="80dp"
        android:layout_height="76dp"
        android:layout_marginBottom="18dp"
        android:background="@drawable/custom_backspace_image_btn"
        app:backgroundTint="@color/light_btn"
        app:layout_constraintBottom_toTopOf="@ id/numbers_8Btn"
        app:layout_constraintEnd_toEndOf="@ id/numbers_8Btn"
        app:layout_constraintStart_toStartOf="@ id/numbers_8Btn"
        app:srcCompat="@drawable/ic_backspace" />

<com.google.android.material.button.MaterialButton
        android:id="@ id/symbol_divideBtn"
        android:layout_width="80dp"
        android:layout_height="76dp"
        android:layout_marginBottom="18dp"
        android:fontFamily="@font/roboto"
        android:stateListAnimator="@null"
        android:text="@string/symbol_divide"
        android:textColor="@color/light_text"
        android:textSize="36sp"
        app:backgroundTint="@color/light_btn"
        app:cornerRadius="18dp"
        app:layout_constraintBottom_toTopOf="@ id/numbers_9Btn"
        app:layout_constraintEnd_toEndOf="@ id/numbers_9Btn"
        app:layout_constraintStart_toStartOf="@ id/numbers_9Btn" />

I am a beginner, so I will be grateful in solving my little problem.

CodePudding user response:

Buttons have some built-in margins that you can't easily get rid of. But you can make any View clickable, such as a TextView or an ImageView. And these classes don't have the built-in margin to worry about. So don't restrict yourself to just Buttons when you want something that's clickable.

  • Related