【问题标题】:What causes TextView to vertical shift是什么导致TextView垂直移位
【发布时间】:2020-06-15 14:00:50
【问题描述】:

是什么导致 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:gravity="center_vertical" 设置为LinearLayout,则视图将居中。你想达到什么目标?
  • 我应该是左上角,默认位置
  • 它也没有和底部对齐,你可以看到它是线性布局高度的 2/3,并且这个值只有在 text2 text-size 改变时才会改变

标签: android textview android-linearlayout


【解决方案1】:

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

要禁用此行为,请添加

android:baselineAligned="false"

到你的线性布局

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 2012-07-05
    • 2013-10-25
    • 1970-01-01
    相关资源
    最近更新 更多