Android Studio中应用运行时按钮显示过小问题求助
Android按钮显示过小的解决方案
按钮显示过小通常和自定义背景、尺寸设置或内边距缺失有关,以下是几种可行的解决方法:
给自定义背景添加内边距
打开你设置的@drawable/roundtext文件(应为shape类型的drawable),在<shape>标签内添加内边距配置,确保按钮有足够的空间:<shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 保留你已有的圆角、颜色等shape配置 --> <padding android:left="16dp" android:top="8dp" android:right="16dp" android:bottom="8dp"/> </shape>直接给Button设置内边距
在Button的布局代码中添加内边距属性,强制撑开按钮尺寸:<Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/roundtext" android:text="Login" android:paddingHorizontal="16dp" android:paddingVertical="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.185" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.584" />设置按钮最小宽高
为按钮指定最小尺寸,避免内容过少导致按钮过小,符合Material Design标准按钮尺寸:android:minWidth="120dp" android:minHeight="48dp"调整文字大小
如果按钮文字过小也会让按钮显得局促,可添加文字大小属性:android:textSize="16sp"
内容的提问来源于stack exchange,提问作者Sanjith Kumar M
相关产品推荐
相关产品推荐

