Как сохранить размер редактируемого текста на прежнем уровне?Android

StackOverflow https://stackoverflow.com/questions/2522369

  •  22-09-2019
  •  | 
  •  

Вопрос

Я знаю атрибут, который заставляет текст "исчезать" в левой части Edittext для сохранения одной строки (singleLine="true").Но моя проблема заключается в том, что я заполняю edittext перед отображением представления...в этом случае все мои редактируемые тексты исчезают с экрана...есть какие-нибудь идеи?спасибо!

Это то, что получается при заполнении пустого Edittext.Все остается на своих местах, а текст с левой стороны исчезает

Скриншот

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

Скриншот

вот код edittext для редактирования :

<EditText android:id="@+id/InscripChampNom"
android:layout_height="wrap_content" android:textSize="14px"
android:inputType="textPersonName" android:layout_marginRight="20dip"
android:singleLine="true" android:textColor="@color/background"></EditText>

Табличное описание определяется следующим образом:

<TableLayout android:layout_width="fill_parent"
android:stretchColumns="1" android:layout_height="fill_parent">

Я также попробовал использовать атрибут

android:layout_width="fill_parent"

и

android:layout_width="wrap_content"

никакого успеха вообще...

Может быть, существует конфликт между типом ввода и singleline?

РЕДАКТИРОВАТЬ Вот полный код моей проблемы :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:background="@color/backgroundzen"
android:layout_gravity="fill" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="6dip"
android:paddingRight="6dip">
<TableLayout style="@style/LayoutWhiteBgrdFillWrap"
    android:paddingLeft="6dip" android:paddingRight="6dip"
    android:stretchColumns="1">
    <TextView android:id="@+id/NomFormationConference" style="@style/textViewTitleRedzenBold"
        android:text="Nom conférence"></TextView>
    <TableRow android:layout_margin="2dip">
        <TextView android:id="@+id/DateSession" android:textColor="@color/textezenrouge"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="date début"></TextView>
        <TextView android:id="@+id/speakerConf" android:textColor="@color/textezenrouge"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="speaker"></TextView>
    </TableRow>
    <TableRow android:layout_margin="2dip">
        <TextView android:id="@+id/InscripNom" android:layout_width="wrap_content"
            android:textColor="@color/background" android:layout_height="wrap_content"
            android:text="@string/nom" android:textStyle="bold"></TextView>
        <EditText android:id="@+id/InscripChampNom"
            android:layout_height="wrap_content" android:textSize="14sp"
            android:layout_width="fill_parent" android:inputType="textPersonName"
            android:layout_marginRight="20dip" android:hint="@string/nomh"
            android:singleLine="true" android:textColor="@color/background"></EditText>
    </TableRow>

//Последняя таблица повторяется 5 раз с различными данными внутри.

Стиль такой- то :

<style name="LayoutWhiteBgrdFillWrap">
    <item name="android:background">@color/backgroundzen</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>
</style>

И вот как я заполняю EditText :

misc = SQLiteDatabase.openDatabase("/data/data/com.mobile.zen/databases/" + Constants.UNVERSIONNED_DATABASE, null,
            SQLiteDatabase.OPEN_READONLY);
    Cursor c = misc.query("MISC", null, null, null, null, null, null);
    if (c.moveToFirst()) {
        do {
            nomInscrit.setText(c.getString(1));
        } while (c.moveToNext());
    }
    c.close();
    misc.close();
Это было полезно?

Решение

Попробуйте добавить android:shrinkColumns="1" на ваш TableLayout сказать ему, что он может заставить EditText элементы должны быть меньшего размера, чтобы соответствовать ширине экрана.

Другие советы

У вас нет android:layout_width атрибут на вашем EditText.Добавьте его или иным образом ограничьте длину поля (например, если оно находится в RelativeLayout, использовать android:layout_alignParentRight="true").

Я просто пытался воспроизвести вашу проблему, но не смог.

Проверь это:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:stretchColumns="1"
    android:layout_height="fill_parent">

    <EditText android:id="@+id/a" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

    <EditText android:id="@+id/b" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

    <EditText android:id="@+id/c" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

</TableLayout>

Возможно, это ошибка в Android.Но один из способов решить эту проблему — указать некоторое значение ширины в поле «Редактировать текст» и указать

Android: StretchColumns = "1"

   <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:background="#ffffff"
android:layout_gravity="fill" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="6dip">
  <TableLayout android:layout_below="@+id/reltable1" android:id="@+id/tablelayout_main" android:layout_width="fill_parent" android:layout_marginRight="10dip" android:layout_marginBottom="10dip" android:layout_height="fill_parent" android:layout_centerInParent="true" android:gravity="center" android:stretchColumns="1">
    <TextView android:id="@+id/NomFormationConference" 
        android:text="Nom conférence"></TextView>
    <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:id="@+id/DateSession"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="date début"></TextView>
        <TextView android:id="@+id/speakerConf" 
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="speaker"></TextView>
    </TableRow>
      <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:id="@+id/InscripNom" android:layout_width="wrap_content"
           android:layout_height="wrap_content"
            android:text="nom" android:textStyle="bold"></TextView>
        <EditText android:id="@+id/InscripChampNom"
            android:textSize="14sp"
            android:inputType="textPersonName"
            android:hint="nomh" android:text="dsfdsfdsfsdfsdfsssssssssssssssssssssssssssssss" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:layout_width="220dip" android:ellipsize="end"></EditText>
    </TableRow>
</TableLayout>
</ScrollView>

Я также добавил свойство высоты и ширины для TableRow.

я не думаю, что tablelayout работает в scrollview.у меня была настройка как таковая, и она не выдает ошибок но эмулятор просто не загружает приложение и сообщает, что перестал работать.я удалил scrollview, и все начало работать.

я думаю, проблема в том, что tablelayout имеет свои собственные полосы прокрутки ему не нужен scrollview и, возможно, эти два конфликта.

<EditText 
    android:id="@+id/InscripChampNom"
    android:layout_height="wrap_content" 
    android:textSize="14px" 
    android:inputType="none" 
    android:layout_marginRight="20dip" 
    android:singleLine="true" 
    android:textColor="@color/background" 
    android:editable="false"
    android:ellipsize="end">
</EditText>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top