0

Здравствуйте! Как правильно указать параметры width/height, чтобы Текст внутри TextView не вылазил за границы экрана и переносился на следующую строку? Я уже пробовал мыслить разумно, затем взял бубен и это не помогло. Текст тупо выходит за границы и пропадает.Провобовал добавлять после присваивания 2й строчки "\n" и Текст в 3ей TextView переносился, но все еще не влазил. Еще: Текста много только в третьей TextView. В 1 и 2 в одну строчку всегда бует влазить, 5-6 символов там. Есть мысля, что высота строки таблицы строится по параметру height первой ячейки. Добавлено: 09,04,2013: Может нужно реализовать перенос по слогам? Как это вообще сделать возможно? Собственно код:

MainActivity:

TableLayout tab = (TableLayout) findViewById(R.id.mytable);
LayoutInflater ltInflater = getLayoutInflater();

      while(cursor.moveToNext())
            {
        ...
        View item = ltInflater.inflate(R.layout.view_items,tab,false);
            item.getLayoutParams().width=LayoutParams.MATCH_PARENT;

    TextView view = (TextView) item.findViewById(R.id.tv_items); 
    TextView view2 = (TextView) item.findViewById(R.id.tv_items2);
    TextView view3= (TextView) item.findViewById(R.id.tv_items3);
    ....//тут я получаю инфу из SQLite курсором и загоняю в строку, затем SetText в TextView и cursor.close(); 
            }

Main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scroll_for_views">
<TableLayout
        android:id="@+id/mytable"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    </TableLayout>

    </ScrollView>
</LinearLayout>

view_items.xml:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv_items"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" >
    </TextView>

    <TextView
        android:id="@+id/tv_items2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" >
    </TextView>

    <TextView
        android:id="@+id/tv_items3"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="TextView" >
    </TextView>

</TableRow>
3
  • я подправил в veiw_items.xml дла каждого textview указал android:singleLine="false" и xml третьего textView : android:layout_height="wrap_content" и теперь переносит слова, но если слово длинное, то часть все равно пропадает, но следующее за ним начинается с новой строки. Тем самым в лэндскейпе все хорошо, а вот в портретном режиме кривовато.
    – Sheldon
    7 апр 2013 в 15:31
  • Попробуйте: <TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
    – Barmaley
    7 апр 2013 в 17:34
  • к сожалению нет. стало вообще в одну строку.
    – Sheldon
    7 апр 2013 в 22:00

5 ответов 5

1
<TableRow
        android:id="@+id/tablelayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:shrinkColumns="0, true">
1
  • Постарайтесь писать более развернутые ответы. 2 апр 2015 в 14:51
0

попробуйте вот это добавить к TextView

android:minLines = "1"
android:maxLines = "100"
android:singleLine = "false"
1
  • нет, тоже не выходит. я даже добавлял еще один ТекстВью, 4ый, в виде линии. Но он игнорирует это и смещает его. Может нужно реализовать перенос по слогам?
    – Sheldon
    9 апр 2013 в 19:42
0

Вот так текст автоматически будет переноситься на следующую строку, даже будь это одно сплошное слово.

<EditText
    android:id="@+id/editDescr"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    android:hint="Description" />
0
<EditText
            android:id="@+id/etBlockText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="500dp"
            android:maxLines="20"
            android:inputType="textMultiLine"...

Все предыдущие варианты пробовал - не работают

-2

Попробуй так:

textView.setText(Html.fromHtml("тут необходимы тег переноса" + твоя_переменная + "закрытие тега переноса"));

Можно еще так:

String x;

    for(твой цикл получения данных) {
     x += твоя_переменная + "\n";
        }
       textView.setText(x);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.