Текст TextView в ListView не имеет многоточия - PullRequest
1 голос
/ 05 января 2012

Я пытаюсь добавить эллипсы в текстовое представление в моем просмотре списка, и оно не работает.

Пожалуйста, ознакомьтесь с моим определением xml ниже.

В этом случае оно не будет отображаться на эмулятореили устройство:

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:focusable="true">
    <ImageView android:id="@+id/imageview" android:layout_width="30dip"
        android:layout_height="30dip" android:layout_centerVertical="true"
        android:layout_alignParentLeft="true" android:src="@drawable/about"
        android:layout_margin="8dip"/>
    <TextView android:id="@+id/title" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_toRightOf="@+id/imageview"
        android:textStyle="bold" android:textColor="#000000"
            android:textSize="15sp" android:lines="1" 
        android:ellipsize="marquee" android:inputType="text"
        android:marqueeRepeatLimit="3" 
        android:layout_marginRight="15dip"
        android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/delete">
    </TextView>
    <ImageButton android:id="@+id/delete" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_centerVertical="true"
        android:layout_alignParentRight="true" android:layout_marginRight="0dip"
        android:layout_margin="5dip" android:src="@drawable/delete_icon"
        />


</RelativeLayout>

И в этом случае оно идет на эмуляторе, а не на устройстве:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ImageView android:id="@+id/imageview"
    android:layout_width="wrap_content"
            android:layout_height="wrap_content"
                         android:layout_centerVertical="true" android:layout_alignParentLeft="true"/>
        <TextView android:id="@+id/title" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_toRightOf="@+id/imageview"
             android:textStyle="bold" android:textColor="#000000"
             android:layout_marginLeft="10dip" android:layout_marginRight="10dip"
            android:textSize="15sp"  android:cacheColorHint="#00000000"> 
        </TextView>
        <TextView android:id="@+id/shortdesc" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_below="@+id/title"
            android:layout_toRightOf="@+id/imageview" 
             android:textSize="15sp"
            android:lines="2" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
             android:layout_marginLeft="10dip" android:layout_marginRight="20dip"
            android:textColor="#413839"  android:cacheColorHint="#00000000">

        </TextView>


</RelativeLayout>

Пожалуйста, помогите, спасибо за ваш ввод и время


Решения Для первого, пожалуйста, посмотрите мои комнеты ниже

Для второго, мне пришлось заменить шатер на конец

<TextView android:id="@+id/shortdesc" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_below="@+id/title"
        android:layout_toRightOf="@+id/imageview" 
         android:textSize="15sp" 
        android:maxLines="2"  android:ellipsize="end" 
         android:layout_marginLeft="10dip" android:layout_marginRight="30dip"
        android:textColor="#413839"  android:cacheColorHint="#00000000"
        android:text="asdfghjmsbvhsfadk vcdfkhreouhjkjfdgdslkfdn bfoiunbf m,cvbkjnfgb kj      nbcdjfkdleoig;dkf nmvnb safdsfrtgdfgdfhg">
    </TextView>

Ответы [ 2 ]

2 голосов
/ 05 января 2012

, если он не работает в режиме просмотра списка, попробуйте сначала отобразить эллиптическое текстовое представление в виде автономного просмотра списка, что может усложнить ситуацию.а также попробуйте использовать атрибут "singleLine = false"

также взгляните на этот вопрос: много информации, связанной с размером текста в эллипсе.

обновлено: мое текстовое представление отлично работает в моем приложении

<TextView 
    android:id="@+id/product_desc" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/img_disclosure"
        android:layout_marginTop="5dip"
        android:layout_marginRight="5dip"
        android:ellipsize="marquee" 
        android:text="this is the sample text to test the ellipsize effect of text view"
        android:textColor="@color/results_sep_color" 
        android:textSize="15sp"
        android:textStyle="bold"
        android:singleLine="false"
        android:maxLines="2"/>

Второе обновление:

<TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lines="1"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="Don't have an account sdsadfsf asdfsdfdsdd abracadabra"

      />
0 голосов
/ 28 мая 2012

Нет необходимости устанавливать атрибуты типа android:scrollHorizontally и android:lines, просто установите android:singleLine="true" и android:ellipsize="marquee", все работает.

Примечание: анимация выделения начинается, когда выбрана строка ListView.

public void setSingleLine(boolean singleLine) {
    // Could be used, but may break backward compatibility.
    // if (mSingleLine == singleLine) return;
    setInputTypeSingleLine(singleLine);
    applySingleLine(singleLine, true, true);
}

private void applySingleLine(boolean singleLine, boolean applyTransformation,
        boolean changeMaxLines) {
    mSingleLine = singleLine;
    if (singleLine) {
        setLines(1);
        setHorizontallyScrolling(true);
        if (applyTransformation) {
            setTransformationMethod(SingleLineTransformationMethod.getInstance());
        }   
    } else {
        if (changeMaxLines) {
            setMaxLines(Integer.MAX_VALUE);
        }   
        setHorizontallyScrolling(false);
        if (applyTransformation) {
            setTransformationMethod(null);
        }   
    }   
}

android.widget.TextView фрагмент кода (начиная с 1.5_r4).

...