Я должен показать длинный текст около 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>
....
Вероятно, вы используете layout_width="wrap_content"
. Это заставит TextView stretch содержать текст в одной строке. Попробуйте использовать layout_width="fill_parent"
(или заданную ширину), а layout_height="wrap_content"
.
Что помогло мне в этой ситуации, было установить 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"/>
попробуйте android:maxEms="15"
.i думаю, это поможет вам
Для текстового просмотра необходимо использовать следующие атрибуты:
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>