Подтвердить что ты не робот

Текст в WordTrap для Android Word

Я пытался перевести окно EditText в перенос слов, но не могу этого сделать.

Я имел дело с гораздо более сложными проблемами при разработке приложений для Android, и кажется, что это должен быть простой процесс.

Однако проблема остается, и у меня есть большое текстовое поле, которое позволяет мне вводить текст только в одну строку, продолжая прямо по горизонтали, прокручивая по горизонтали при вводе текста.

Вот код XML для объекта EditText из моего файла макета.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/myWidget48"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
 <ScrollView
    android:id="@+id/myScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    >
    <LinearLayout
        android:id="@+id/widget37"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
    >

<EditText
        android:id="@+id/txtNotes"
        android:layout_width="300px"
        android:layout_height="120px"
        android:scrollbars="vertical"
        android:textSize="18sp"
        android:gravity="left"
        android:layout_marginTop="10dip"
        android:inputType="textCapSentences"
        >
    </EditText>
</LinearLayout>
</ScrollView>
</LinearLayout>
4b9b3361

Ответ 1

Помимо поиска источника проблемы, я нашел решение. Если используется android:inputType, то для включения многострочной поддержки необходимо использовать textMultiLine. Кроме того, использование inputType заменяет код android:singleLine="false". Если вы используете inputType, то, чтобы повторить, необходимо использовать textMultiLine или объект EditText будет состоять только из одной строки без переноса слов.

Изменить: Спасибо Jacob Malliet за предоставление дальнейших хороших советов по этому вопросу. Он предложил установить для свойства boolean scrollHorizontally значение false, 'android:scrollHorizontally="false"'.

Пример XML-кода:

<EditText
    android:id ="@+id/edtInput"
    android:layout_width ="0dip" 
    android:layout_height ="wrap_content" 
    android:layout_weight ="1" 
    android:inputType="textCapSentences|textMultiLine"
    android:maxLines ="4" 
    android:maxLength ="2000" 
    android:hint ="@string/compose_hint"
    android:scrollHorizontally="false" />

Ответ 2

Хорошо, я понял, вы должны установить android:scrollHorizontally="false" для своего EditText в вашем xml. Я уверен, что это должно сработать.

Ответ 3

Предположим, что вы просто хотите сначала создать одну строку, затем разверните ее до 5 строк, и вы хотите иметь максимум 10 строк.

<EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/etMessageBox"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:autoLink="all"
                    android:hint="@string/message_edit_text_hint"
                    android:lines="5"
                    android:minLines="1"
                    android:gravity="top|left"
                    android:maxLines="10"
                    android:scrollbars="none"
                    android:inputType="textMultiLine|textCapSentences"/>

Увеличивая android:lines, вы можете определить его количество строк.

Ответ 4

Я понял это. Линия,

android:inputType="textCapSentences"

была проблема. Добавление этой строки в объект EditText сделает объект единственной строкой EditText и не позволит переносить слова или разрешить пользователю нажимать 'Enter' для вставки строки или возврата каретки в EditText.

Ответ 5

вы должны добавить следующий атрибут в свой edittext.

android:inputType="textMultiLine"

Также, если вы задаете высоту или задаете максимальные значения edittext для определенного значения, она будет прокручиваться, когда вы набрали много символов.

Ответ 6

Закрытие всей активности в режиме прокрутки и размещение следующего текста редактирования в линейном макете работали как прелесть для меня.

Текст редактирования будет прокручиваться по вертикали, нажимая Enter, код следующим образом

<EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:hint="Enter somehting"
            android:inputType="textMultiLine"
            android:maxLength="2000"
            android:maxLines="6"
            android:scrollHorizontally="false"
            android:scrollbars="vertical" > 

Ответ 7

Попробуйте это, меняя гравитацию на верх | левый, работал для меня вместе с типом ввода textmultiline

<EditText
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@color/color_red"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="top|left"
    android:inputType="textMultiLine|textCapSentences"
    android:lines="10"
    android:maxWidth="200dp"
    android:maxLength="200"
    android:maxLines="10"
    android:singleLine="false"
    android:textColor="@android:color/white"
    android:textSize="26sp" />

Ответ 9

Также установите ширину родительского макета, (свойство Layout_width). Например, layout_width = 250sp

в противном случае EditText или TextView не переносятся на следующую строку, пока не дойдут до конца мобильной границы. Так что определите Layout_width

Ответ 10

Примечание: шаг 1 - создайте собственный класс для editText wordWrap.

Android не имеет этого свойства. Но вы можете заменить все ломающиеся символы с помощью ReplacementTransformationMethod.

public class WordBreakTransformationMethod extends ReplacementTransformationMethod
{
    private static WordBreakTransformationMethod instance;
    private WordBreakTransformationMethod() {}

    public static WordBreakTransformationMethod getInstance()
    {
        if (instance == null)
        {
            instance = new WordBreakTransformationMethod();
        }
        return instance;
    }

    private static char[] dash = new char[] {'-', '\u2011'};
    private static char[] space = new char[] {' ', '\u00A0'};

    private static char[] original = new char[] {dash[0], space[0]};
    private static char[] replacement = new char[] {dash[1], space[1]};

    @Override
    protected char[] getOriginal()
    {
        return original;
    }

    @Override
    protected char[] getReplacement()
    {
        return replacement;
    }
}

step 2 - In Activity , write below code,

В Android:

myEditText.setTransformationMethod(WordBreakTransformationMethod.getInstance());

В Котлине:

myEditText.setTransformationMethod= WordBreakTransformationMethod.getInstance

В XML:

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

    <EditText
        android:id="@+id/myEditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:inputType="textCapSentences|textMultiLine"
        android:scrollHorizontally="false" />
</LinearLayout>

Ответ 11

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/table"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    >  
     <TableRow
        android:id="@+id/newRow">
        <LinearLayout
             android:layout_width="fill_parent"
             android:orientation="vertical"
             android:layout_height="wrap_content"
             android:gravity="left"
             android:paddingBottom="10dip">
            <TextView  
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Some Text"
            />
        </LinearLayout>
        </TableRow>

        <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TableRow>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="10dip">

    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:text="Some Text"
        android:paddingBottom="5dip"
        />     
    <EditText 
        android:id="@+id/editbox"  
        android:layout_width="wrap_content" 
        android:layout_height="150px"
        android:gravity="top"   
        android:inputType="textFilter"
        android:scrollHorizontally="false"      
        />  

</RelativeLayout>
</TableRow>
<TableRow>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button 
        android:id="@+id/btnone"  
        android:layout_width="3dip" 
        android:layout_height="wrap_content"
        android:layout_margin="2dip"
        android:layout_weight="1"
        android:text="Btn"
        />          
    <Button 
        android:id="@+id/btntwo"  
        android:layout_width="3dip" 
        android:layout_height="wrap_content"
        android:layout_margin="2dip"
        android:layout_weight="1"
        android:text="Btn"
        />    
 </LinearLayout>
 </TableRow>
 </TableLayout>