строки textView - совет - PullRequest
       3

строки textView - совет

0 голосов
/ 09 декабря 2011
<RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:adjustViewBounds="true"
            android:src="@drawable/icon" />

        <TextView
            android:id="@+id/fullnameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/wayimageView"
            android:textColor="@color/list_text_color"
            android:textSize="16dp"
            android:singleLine="false"
             />
    <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:adjustViewBounds="true"
            android:src="@drawable/icon" />
    </RelativeLayout>

Я хочу установить имя справа от imageView.Это хорошо, но есть одна проблема.Когда имя слишком длинное, оно попадает под второе изображение.Есть ли способ указать максимальное количество символов в строке в textView (например, 10), когда размер символов равен 10, он автоматически переходит ко второй строке.

Ответы [ 4 ]

3 голосов
/ 09 декабря 2011

Лучший и самый простой способ - установить имя слева от второго изображения.

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="10dp"
    android:adjustViewBounds="true"
    android:src="@drawable/icon" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentright="true"
    android:layout_marginRight="10dp"
    android:adjustViewBounds="true"
    android:src="@drawable/icon" />

<TextView
    android:id="@+id/fullnameTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/imageView2"
    android:layout_toRightOf="+@id/wayimageView"
    android:textColor="@color/list_text_color"
    android:textSize="16dp" />

0 голосов
/ 09 декабря 2011

Вы можете использовать это

    android:ellipsize="end" 
    android:maxLines="1"
    android:scrollHorizontally="true"

Если ваш текст выходит за рамки ширины textview, то в конце будут добавлены точки "...".

Если код выше, нерабочий добавить андроид: singleLine = "true"

0 голосов
/ 09 декабря 2011

Укажите размер textview, например: android: layout_width = "xdp" и android: maxLines = "2" или все, что вы хотите.

0 голосов
/ 09 декабря 2011

Вы можете ограничить максимальную ширину вашего TextView:

android:maxWidth="10dp"

...