【发布时间】:2019-01-28 21:23:38
【问题描述】:
我有 2 个相邻的 TextViews,每个都有不同的字符串,具有不同的字体大小。我希望文本在每个TextView 中具有相同的基线。我该怎么做?
这是我的布局:
<LinearLayout
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="@color/colorAccentLight"
android:textSize="18sp"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom"
android:textAlignment="gravity"
android:text="30"
/>
<TextView
android:background="@color/colorAccent"
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom"
android:textAlignment="gravity"
/>
</LinearLayout>
这是当前行为,请注意 2 个TextViews 有不同的基线(“hello”低于 30),因为每个 TextView 的字体大小不同。
【问题讨论】:
-
还不能写 cmets。你看here了吗?
-
谢谢。我最终使用了这个解决方案(将
TextViews 包装在RelativeLayout中并使用“align_baseline”属性。
标签: android android-layout textview android-xml