首页 > 解决方案 > Android TextView Gravity BOTTOM 意外行为

问题描述

我当前的 Android 项目要求在 a 中显示多行文本(最多 3 行)TextView并将文本放置在文本视图的底部。

我的 TextView 定义如下:-

<TextView
    android:id="@+id/my_title"
    android:layout_width="@dimen/image_width"
    android:layout_height="@dimen/image_height"
    android:layout_alignTop="@+id/other_title"
    android:layout_marginTop="@dimen/span_eight"
    android:layout_toEndOf="@+id/dot"
    android:maxLines="3"
    android:gravity="bottom"
    android:padding="2dp"
    android:textColor="@android:color/white"
    android:textSize="@dimen/text_twelve" />

当要显示的文本为 3 行或更少时,文本将按预期显示。

但是,当它超过 3 行时,文本的开头将被截断。

例如

" Artificial cells, nanomedicine, and biotechnology"

显示为

"`cine, and biotechnology`"

我需要的是它显示为

"`Artificial cells, nanom`"

我如何达到预期的效果?

标签: androidtextview

解决方案


尝试;

android:gravity="bottom|start"

代替

android:gravity="bottom"

推荐阅读