android - 当 textSize 超过 maxHeight 时,按钮文本不居中
问题描述
我正在尝试将按钮内的一些文本垂直居中,但是当 textSize 超过按钮的高度时,文本会与顶部对齐,就像 android:gravity="top" 而不是 android:gravity="center"
我通过添加 android:includeFontPadding="false" 和 android:paddingTop="0dp" 稍微改进了结果,但文本没有居中。我希望文本垂直居中,因此在按钮上方和下方被剪辑。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:maxHeight="40dp"
android:paddingTop="0dp"
android:text="Button"
android:textSize="60dp" />
</android.support.constraint.ConstraintLayout>
这是布局的屏幕截图...
解决方案
尝试使用负填充或边距来向上移动文本。
推荐阅读
- r - 如何提高此 R 代码的性能?
- weblogic - Weblogic 工作管理器 Stuck Thread Action wlst.sh
- javascript - 我如何知道两个 html 元素(div、map 或其他)是否有边框?
- sql - 选择具有在另一个表中列出的值组合的行
- python - 将 SQL Lag over PartitionBy 查询转换为 pandas
- java - 如何获取 DateTimePicker 值,如果它的值在 java 中为空,则可能抛出 true
- json - 有没有办法在不读取整个数据集的情况下获取 pyspark 中数据框的列名?
- java - 仅瓷砖应用
- regex - IIS 用多个值重写规则一查询参数
- css - 是否使用显示属性来响应不良行为?