• android中给TextView设置属性ellipsize


    1,ellipsize等于marquee,跑马灯效果

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#EEEEEE" >

            <TextView
                android:id="@+id/textview"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="#EEEE00"
                android:ellipsize="marquee"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:marqueeRepeatLimit="marquee_forever"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="@string/hello_world"
                android:textSize="15dp"
                android:textColor="#FF0000" />

    </RelativeLayout>

    运行效果是:

    从右向左循环滚动。

    2,ellipsize等于end

    <TextView
        android:id="@+id/textview"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#EEEE00"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="@string/hello_world"
        android:textSize="15dp"
        android:textColor="#FF0000" />

    运行屏幕截图:

    )N)~WB79%DH}J3``}3K{%$H

    3,ellipsize等于start

    <TextView
        android:id="@+id/textview"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#EEEE00"
        android:ellipsize="start"
        android:singleLine="true"
        android:text="@string/hello_world"
        android:textSize="15dp"
        android:textColor="#FF0000" />

    运行屏幕截图:

    PF{5Q%3W(6`Y$VDP8W%$0LW

    4,ellipsize等于middle

    <TextView
        android:id="@+id/textview"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#EEEE00"
        android:ellipsize="middle"
        android:singleLine="true"
        android:text="@string/hello_world"
        android:textSize="15dp"
        android:textColor="#FF0000" />

    运行屏幕截图:

    W6){B@45BQ{O(_0A0{4XI3V

    5,ellipsize等于none

    <TextView
    android:id="@+id/textview"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="#EEEE00"
    android:ellipsize="none"
    android:singleLine="true"
    android:text="@string/hello_world"
    android:textSize="15dp"
    android:textColor="#FF0000" />

    运行屏幕截图:

    RKA7E7Z[~PMOXMTZFG(MK)G

    6,上述5种用法在代码中设置也可以达到效果

    textView.setEllipsize(TruncateAt.MARQUEE);

    textView.setEllipsize(TruncateAt.END);

    textView.setEllipsize(TruncateAt.START);

    textView.setEllipsize(TruncateAt.MIDDLE);

    或者,

    tv.setEllipsize(TruncateAt.valueOf("END"));

    tv.setEllipsize(TruncateAt.valueOf("START"));

    tv.setEllipsize(TruncateAt.valueOf("MIDDLE"));

    tv.setEllipsize(TruncateAt.valueOf("MARQUEE"));

  • 相关阅读:
    又是一年叶落时(二)
    动态规划 之 区间DP练习
    [hdu2255] 奔小康赚大钱
    [洛谷P1967] 货车运输
    [UVA1494] Qin Shi Huang's National Road System
    斜率优化总结
    latex一些有用的写法
    [YTU]_2384 ( 矩形类中运算符重载【C++】)
    [YTU]_2442( C++习题 矩阵求和--重载运算符)
    [YTU]_2640( 编程题:运算符重载---矩阵求和)
  • 原文地址:https://www.cnblogs.com/fengzhblog/p/3080392.html
Copyright © 2020-2023  润新知