android - 将符号放在按钮的中心

标签 android android-button

我试图在按钮的中心设置“+”符号,但它在底部

<Button android:background="@drawable/zoom_button_background"
        android:layout_height="40dp"
        android:layout_width="40dp"
        android:textSize="24sp"
        android:textColor="@color/black2"
        android:text="+"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="160dp"
        android:layout_marginRight="10dp"/>

我想将 textSize 设置为 42sp,但是当我这样做时,plus 不在中心。我怎样才能让他在一个中心?

最佳答案

发生这种情况是因为您设置的文本大小 (42sp) 对于给定的按钮大小 (40dp x 40dp) 来说太大了。不要显式设置按钮的大小,而是使用 wrap_content 来设置宽度和高度。

关于android - 将符号放在按钮的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8091450/

相关文章:

Android edittext无法进入下一个edittext

android - Android 8中使用Shape Drawable设置Button的背景颜色和边框颜色

javascript - 使用地理定位 API 计算我的速度 javascript

android - WallpaperService.Engine.onTouchEvent 不接收 ACTION_MOVE 事件

Android - 创建和运行快捷方式

android - 按钮的随机大小和位置 : unexpected behavior

Android:MaterialButton 覆盖 Style 中的 textColor

android - 试图在 Android 中将按钮推到线性布局的底部

android - 未处理 fragment 的 AlertDialog 的单击事件中的自定义取消按钮

android - Laravel:如何为 web、android 和 ios 构建实时聊天?