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"));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM