Android TextView Gravity BOTTOM 意外行为
Android TextView Gravity BOTTOM unexpected behaviour
我当前的 Android 项目需要在 TextView
中显示多行文本(最多 3 行)并将文本放在文本视图的底部。
我的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`"
如何达到预期的效果?
试试看;
android:gravity="bottom|start"
而不是
android:gravity="bottom"
使用:
android:ellipsize="end"
将此 属性 添加到您的 TextView
您将看到文本从开始到第三行的末尾有 3 个点 (...) 表示文本超过 3 行.
使用:
android:gravity="start"
重力中的底部值将改变显示行为。您改变 TextView 的高度和边距。
我当前的 Android 项目需要在 TextView
中显示多行文本(最多 3 行)并将文本放在文本视图的底部。
我的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`"
如何达到预期的效果?
试试看;
android:gravity="bottom|start"
而不是
android:gravity="bottom"
使用:
android:ellipsize="end"
将此 属性 添加到您的 TextView
您将看到文本从开始到第三行的末尾有 3 个点 (...) 表示文本超过 3 行.
使用:
android:gravity="start"
重力中的底部值将改变显示行为。您改变 TextView 的高度和边距。