4

Как сделать, чтобы EditText не увеличивался в стороны, когда в него вводят текст?


Код разметки (EditText'ы в первых двух LinearLayout'ах):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_weight="0.45"
            android:text="@string/id_sender"
            android:textColor="@color/black"
            android:textSize="17dp" />

        <EditText
            android:id="@+id/edittext_sender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.55"
            android:gravity="center"
            android:lines="1"
            android:textColor="@color/black"
            android:textSize="17dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_weight="0.45"
            android:text="@string/id_recipient"
            android:textColor="@color/black"
            android:textSize="17dp" />

        <EditText
            android:id="@+id/edittext_recipient"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.55"
            android:gravity="center"
            android:lines="1"
            android:textColor="@color/black"
            android:textSize="17dp" />
    </LinearLayout>

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:layout_gravity="right"
            android:text="@string/login" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Button
            android:id="@+id/button_start"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/start_forwarding" />

        <Button
            android:id="@+id/button_stop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/stop_forwarding" />
    </LinearLayout>
</LinearLayout>
11
  • Жестко задать размеры поля, не?
    – Ivan Vovk
    6 апр 2016 в 19:32
  • @IvanVovk, я задал в weight, но он все равно разрастается, "выдавливая" TextView.
    – user189127
    6 апр 2016 в 19:36
  • Попробуйте задать width:)
    – Ivan Vovk
    6 апр 2016 в 19:38
  • @IvanVovk, низя :)).
    – user189127
    6 апр 2016 в 19:40
  • может тогда считать количество символов, которые можно ввести в текстовое поле
    – Ivan Vovk
    6 апр 2016 в 19:44

1 ответ 1

7

android:layout_width="wrap_content" нужно поменять на android:layout_width="0dp"

<EditText
        android:id="@+id/edittext_sender"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.55"
        android:gravity="center"
        android:lines="1"
        android:textColor="@color/black"
        android:textSize="17dp" />

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.