【发布时间】:2020-11-05 09:59:09
【问题描述】:
所以我有 3 个垂直对齐的 TextView。第二个字体更大。
现在,如果第二个 TextView 包含一个以 e.g. 开头的字符串一个 'B' 看起来视图是缩进的:
这是我的 XML 布局:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView style="@style/TextAppearance.LabelSmall"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1" />
<TextView style="@style/TextAppearance.LabelBig"
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B TextView2" />
<TextView style="@style/TextAppearance.LabelSmall"
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView3" />
</LinearLayout>
这里是对应的styles.xml文件:
<resources>
<style name="TextAppearance.LabelBig" parent="TextAppearance.MaterialComponents.Headline3">
<item name="fontFamily">@font/opensans_regular</item>
<item name="android:fontFamily">@font/opensans_regular</item>
<item name="android:textSize">48sp</item>
</style>
<style name="TextAppearance.LabelSmall" parent="TextAppearance.MaterialComponents.Body1">
<item name="fontFamily">@font/opensans_regular</item>
<item name="android:fontFamily">@font/opensans_regular</item>
<item name="android:textSize">16sp</item>
</style>
</ressources>
有没有办法让这些 TextView 看起来同样缩进?
感谢您的帮助。
【问题讨论】:
-
你试过 android:includeFontPadding="false"
-
@PankajKumar 我做到了。它什么也没改变。同样it seems like
includeFontPadding只涉及文本height。 -
看来你是对的
-
实际上问题出在排版上,为其他文本设置了像素,例如T 和 B 开始索引是不同的,所以如果你使用 T 和 48sp 你会注意到没有空格,所以如果你知道在这种情况下文本是硬编码的,你可以使用 android:paddingStart="-3dp"
-
您是否尝试在“较小”
TextViews 的开头添加边距?
标签: android android-layout kotlin textview android-xml