为什么ImageButton和按钮具有相同尺寸的不同高度?

发布于 2025-02-09 04:39:30 字数 1506 浏览 2 评论 0原文

问题是以下内容。 我有一个图像键和一个按钮,它们的高度和宽度相同。但是图像键被拉伸以覆盖整个区域,但按钮不是。我需要按钮才能完全填充该区域。

屏幕截图和代码:

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" />

我是初学者,所以我会很高兴我能在解决我的解决方案。小问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑脸一如从前 2025-02-16 04:39:30

按钮 S具有一些您无法轻易摆脱的内置边距。但是您可以单击任何view,例如textViewimageView。而且这些课程没有内置的边距可以担心。因此,当您想要可单击的东西时,不要将自己限制在按钮时。

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.

山人契 2025-02-16 04:39:30

要制作按钮imageButton具有相同的高度:硬码imagebutton高度和按钮 minheight

”“在此处输入图像说明”

在下面调整属性,您可以完全控制button margins and Inters:

android:insetTop="0dp"
android:insetBottom="0dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:padding="0dp"

To make Button and ImageButton have the same height: hardcode ImageButton height and Button minHeight:

enter image description here

Adjusting below properties gives you full control of Button margins and insets:

android:insetTop="0dp"
android:insetBottom="0dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:padding="0dp"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文