所以我有3个垂直对齐的TextViews。第二个有一个更大的字体。
现在,如果第二个TextView包含一个以'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>
有没有办法让这些TextViews看起来同样缩进?
谢谢你的帮助。
发布于 2020-11-05 10:34:54
您不需要为单行文本使用三个文本视图,只需使用spannable。
在这里找到一些信息:https://medium.com/androiddevelopers/spantastic-text-styling-with-spans-17b0c16b4568
https://stackoverflow.com/questions/64694873
复制相似问题