android - Android中的圆角按钮不扩大尺寸
问题描述
这篇文章有很多解释如何在 Android 中创建圆形按钮的答案。但几乎所有答案最终都会扩大按钮的大小。
例如,在此布局中,请注意顶部按钮(带有圆角的按钮)的填充比其他按钮多得多。
这是没有圆角的按钮的代码;
<Button
android:id="@+id/useKeyboardButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/use_keyboard_msg"
app:layout_constraintBottom_toTopOf="@+id/privacyPolicyButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/enableKeyboardButton"
style="@style/Widget.AppCompat.Button.Colored"
/>
这是圆角按钮的代码:
<Button
android:id="@+id/enableKeyboardButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/enable_keyboard_msg"
app:layout_constraintBottom_toTopOf="@+id/useKeyboardButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="@style/Widget.AppCompat.Button.Colored"
android:background="@drawable/rounded_corners"
/>
背景是这个可绘制的:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorAccent"/>
<corners android:radius="10dp"/>
</shape>
解决方案
尝试删除样式属性并仅设置背景可绘制对象。
推荐阅读
- qt - 是否可以在 QML 中的 mouseX,mouseY 下获取任何子组件
- javascript - 使用此 GET 请求进行缓存如何工作?
- three.js - 如何在 PlaneGeometry 中添加纹理
- time - 在 Gremlin 控制台上显示时间
- django - 跨越多行的django标签
- erlang - 如何在erlang中匹配子字符串忽略大小写
- java - 如何避免文件操作中的并发操作(保存/删除)
- c# - 属性集,在其他类中为空。C#
- django - Django 模型 Slug 字段 unique_for_month 不起作用
- python - 将 Python 请求与 Siteminder 一起使用