2016-11-18 7 views
-1

예를 들어, "Firstword secondword"라는 단어가 두 개 있습니다. Textview에는 1 줄이 있고 너비가 크지 않으므로 첫 단어가 표시되고 나머지 공간에 맞추기 위해 두 번째부터 길게 표시됩니다. [Firstword______] 두 번째 단어의 부분 가시성을 얻는 방법은 무엇입니까? 이와 같이 [Firstword secon] 또는 [Firstword seco ...] (줄임표 포함). 가능한가? 일부 항목에서는 필자가 원하는 것은 줄임표를 사용할 때 기본 동작이지만 내 경우에는 그렇지 않다는 것을 알았습니다.TextView는 내가 겉으로 드러내는 마지막 단어를 숨 깁니다.

편집 : android : ellipsize = "end"android : maxLines = "1"은 XML 레이아웃 미리보기에서만 작동하지만 런타임에는 작동하지 않습니다.

답변

1

해결책을 찾았습니다.

이 XML :

<?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="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!" 
     android:id="@+id/tv1" 
     android:textColorLink="@android:color/holo_blue_dark" 
     android:ellipsize="end" 
     android:singleLine="true"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!" 
     android:id="@+id/tv2" 
     android:textColorLink="@android:color/holo_blue_dark" 
     android:ellipsize="end" 
     android:lines="1"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!" 
     android:id="@+id/tv3" 
     android:textColorLink="@android:color/holo_blue_dark" 
     android:ellipsize="end" 
     android:maxLines="1"/> 
</LinearLayout> 

enter image description here

OK 같은 디자인의 미리보기에서 렌더링, 모든 ellipsizes 여기서 일. 실제 기기에서 보이는 것처럼 enter image description here

android : singleLine = "true"는 사용되지 않지만 더 이상 사용되지 않습니다. 3 개의 기기에서 테스트되었습니다.

1

당신의 텍스트 뷰에

안드로이드를 다음 추가 : 난 당신이 프로그램이 텍스트 뷰 설정 원하는 것을 이해한다면

<TextView 
    android:id="@+id/myTextView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="end" 
    android:maxLines="1"/> 
+0

그래, XML 레이아웃 미리보기에서 작동합니다. 하지만 런타임에 작동하지 않습니다. [Firstword ..._____] 표시 고유 한 ttf 서체와 함께 사용자 지정 TextView를 사용하고 있기 때문일 수 있습니까? –

+0

textView.setEllipsize (TextUtils.TruncateAt.END); – PravinCG

+0

textView.setEllipsize (TextUtils.TruncateAt.END)도 작동하지 않습니다. 기본 TextView도 있습니다. –

0

maxLines = "1": ellipsize는 = 안드로이드 "종료" :

textView.setEllipsize(TextUtils.TruncateAt.END); 
+0

이것도 작동하지 않으며 이유를 이해하지 못합니다 ... –