Android: отображение длинного текста для TextView

1

Я должен показать длинный текст около 250 символов (одна строка, новые строки или перерывы). для TextView моей активности.

Я использовал textType как textMultiLine для моего представления макета, и из активности я использовал метод view.setText(), передав длинный текст.

Но текст выводится из видимого экрана.

Как это исправить?

Спасибо, Нехата

+++ Редактировать +++++

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:background="@drawable/bg" 
android:gravity="center_horizontal"
android:id="@+id/rootView">
<ScrollView android:id="@+id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:layout_marginLeft="8dp" android:layout_marginRight="8dp"
    android:minWidth="310dp" android:scrollbarStyle="outsideOverlay"
    android:scrollbars="vertical">
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <FrameLayout android:id="@android:id/tabcontent"
                android:layout_width="fill_parent" android:layout_height="fill_parent">


                <LinearLayout android:id="@+id/tabContentPostDetails"
                    android:layout_width="wrap_content" android:orientation="vertical"
                    android:layout_height="fill_parent">

                    <TableLayout android:id="@+id/TableLayout01"
                        android:layout_width="fill_parent" android:layout_height="wrap_content"
                        android:gravity="center"
                        android:background="@drawable/transparent_border_shape">
                        <TableRow android:layout_marginBottom="5dip">
                            <LinearLayout android:orientation="horizontal"
                            android:layout_width="fill_parent" android:layout_height="wrap_content">
                                <TextView android:id="@+id/csPostTitle"
                                    android:padding="3dip" android:textSize="7pt"
                                    android:textColor="@color/Black"  
                                    android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textMultiLine"/>
                            </LinearLayout>
                        </TableRow>

                        ....
Теги:
android-layout

4 ответа

2

Вероятно, вы используете layout_width="wrap_content". Это заставит TextView stretch содержать текст в одной строке. Попробуйте использовать layout_width="fill_parent" (или заданную ширину), а layout_height="wrap_content".

  • 0
    Привет Грегори, я пытался с "fill_parent", но все же я не вижу весь текст.
  • 0
    Не могли бы вы опубликовать скриншот того, что у вас есть и ваш макет?
Показать ещё 1 комментарий
1

Что помогло мне в этой ситуации, было установить layout_gravity="fill_vertical" следующим образом:

    <TextView
        android:id="@+id/list_e_taskdesc"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="fill_vertical"
        android:text="@string/empty_label1"/>
1

попробуйте android:maxEms="15".i думаю, это поможет вам

  • 0
    Идеальное решение! при добавлении текста в тот же TextView, и вы хотите ограничить количество букв в любой строке в представлении.
0

Для текстового просмотра необходимо использовать следующие атрибуты:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:maxLines="10"

Измените 10 на любое число, которое работает для вас.

Я тестировал макет:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#ffffff"
    android:gravity="center_horizontal"
    android:id="@+id/rootView">
    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:minWidth="310dp"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <LinearLayout
                    android:id="@+id/tabContentPostDetails"
                    android:layout_width="wrap_content"
                    android:orientation="vertical"
                    android:layout_height="fill_parent">

                    <TableLayout
                        android:id="@+id/TableLayout01"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:background="#ffffff">
                        <TableRow 
                            android:layout_marginBottom="5dip"
                            android:background="#ff0000"
                            >
                            <TextView
                                android:id="@+id/csPostTitle"
                                android:background="#00ff00"
                                android:padding="3dip"
                                android:textSize="7pt"
                                android:textColor="#000000"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:inputType="textMultiLine"
                                android:maxLines="10"
                                android:text="this is a very long text. so long that it does not ghave any breaks whasoever. this is a test to see if the line dissplayes proper;ly." />

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content">
                            </LinearLayout>
                        </TableRow>
                    </TableLayout>
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
  • 0
    Привет, Мандель, это не работает для меня, тем не менее, текст отображается в одной строке, и я не могу увидеть текст, который находится за пределами видимого экрана.
  • 0
    Смотрите макет, который я тестировал. Возможно, есть некоторые другие изменения, которые я забыл упомянуть. Сравните приведенный выше макет с тем, который у вас есть.
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню