导致TextView垂直移动的原因

问题描述 投票:0回答:1

为什么Text1会垂直移动?Text1的垂直移动也取决于Text2的字体大小,而不是取决于容器或text2的高度。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text1"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="68sp"
        android:text="text2"/>
</LinearLayout>
android textview android-linearlayout
1个回答
2
投票

默认情况下,LinearLayout会尝试对齐TextViews基线(文本的底部边缘)。

要禁用这种行为,请添加

android:baselineAligned="false"

到您的LinearLayout

© www.soinside.com 2019 - 2024. All rights reserved.