为什么ImageButton和按钮具有相同尺寸的不同高度?
问题是以下内容。 我有一个图像键和一个按钮,它们的高度和宽度相同。但是图像键被拉伸以覆盖整个区域,但按钮不是。我需要按钮才能完全填充该区域。
屏幕截图和代码:
<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
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按钮
S具有一些您无法轻易摆脱的内置边距。但是您可以单击任何view
,例如textView
或imageView
。而且这些课程没有内置的边距可以担心。因此,当您想要可单击的东西时,不要将自己限制在按钮
时。Button
s have some built-in margins that you can't easily get rid of. But you can make anyView
clickable, such as aTextView
or anImageView
. And these classes don't have the built-in margin to worry about. So don't restrict yourself to justButton
s when you want something that's clickable.要制作
按钮
和imageButton
具有相同的高度:硬码imagebutton
高度和按钮
minheight
:在下面调整属性,您可以完全控制
button
margins and Inters:To make
Button
andImageButton
have the same height: hardcodeImageButton
height andButton
minHeight
:Adjusting below properties gives you full control of
Button
margins and insets: