2022-03-09 TextView 内容过长的话 跑马灯效果 省略号在结尾、开头、中间效果

一、textview中内容过长的话自动换行,如果想换行可以使用android:ellipsize与android:singleine。

android:ellipsize = "end"    省略号在结尾

android:ellipsize = "start"   省略号在开头

android:ellipsize = "middle"     省略号在中间

android:ellipsize = "marquee"  跑马灯

android:singleline = "true"

二、布局文件

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/show_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="孤雁不饮啄,飞鸣声念群。谁怜一片影,相失万重云?望尽似犹见,哀多如更闻。野鸦无意绪,鸣噪自纷纷。"
        android:singleLine="true"
        android:textSize="50dp"/>

    <TextView
        android:id="@+id/show_tv_end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="孤雁不饮啄,飞鸣声念群。谁怜一片影,相失万重云?望尽似犹见,哀多如更闻。野鸦无意绪,鸣噪自纷纷。"
        android:singleLine="true"
        android:textSize="50dp"/>
    <TextView
        android:id="@+id/show_tv_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="start"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="孤雁不饮啄,飞鸣声念群。谁怜一片影,相失万重云?望尽似犹见,哀多如更闻。野鸦无意绪,鸣噪自纷纷。"
        android:singleLine="true"
        android:textSize="50dp"/>
    <TextView
        android:id="@+id/show_tv_middle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="middle"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="孤雁不饮啄,飞鸣声念群。谁怜一片影,相失万重云?望尽似犹见,哀多如更闻。野鸦无意绪,鸣噪自纷纷。"
        android:singleLine="true"
        android:textSize="50dp"/>

</LinearLayout>

猜你喜欢

转载自blog.csdn.net/qq_37858386/article/details/123382710