Не удается получить текст редактирования для работы внутри прокрутки - PullRequest
1 голос
/ 05 ноября 2019

Я пытаюсь создать страницу, на которой я могу поместить информацию в базу данных, но на одной странице слишком много места. Я поместил его в scrollView, чтобы справиться с этим, но editText сейчас не работает, он не будет показывать подсказки или позволять мне вводить информацию в него.

Вот мой код:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".informationActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginBottom="300dp"
                app:srcCompat="@drawable/bottle" />

            <TextView
                android:id="@+id/nameTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                android:text="Name" />

            <EditText
                android:id="@+id/nameEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:ems="10"
                android:hint="Write here"
                android:inputType="textPersonName" />

            <TextView
                android:id="@+id/priceTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                android:text="Price" />

            <EditText
                android:id="@+id/priceEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:ems="10"
                android:hint="...."
                android:inputType="textPersonName" />

            <TextView
                android:id="@+id/goesWithTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                android:text="What does it go best with?" />

            <EditText
                android:id="@+id/goesWithEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:ems="10"
                android:hint="...."
                android:inputType="textPersonName" />

            <TextView
                android:id="@+id/whereTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                android:text="Where did you get it?" />

            <EditText
                android:id="@+id/whereEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:ems="10"
                android:hint="...."
                android:inputType="textPersonName" />

        </LinearLayout>
    </ScrollView>

Я не уверен, как подойти к нему без scrollView, но больше ничего не работает. Есть другой формат, который я мог бы использовать, чтобы исправить это, или это XML, который является проблемой?

Ответы [ 3 ]

0 голосов
/ 05 ноября 2019

Поскольку ширина вашего EditText равна 0.

Заменить строку ниже

android:layout_width="0dp"

на

android:layout_width="match_parent"
0 голосов
/ 05 ноября 2019

Изменить ширину макета редактирования текста 0 на match_parent или wrap_content

Проверить код сейчас

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

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="300dp"
            app:srcCompat="@drawable/bottle" />

        <TextView
            android:id="@+id/nameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:text="Name" />

        <EditText
            android:id="@+id/nameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:ems="10"
            android:hint="Write here"
            android:inputType="textPersonName" />

        <TextView
            android:id="@+id/priceTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:text="Price" />

        <EditText
            android:id="@+id/priceEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:ems="10"
            android:hint="...."
            android:inputType="textPersonName" />

        <TextView
            android:id="@+id/goesWithTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:text="What does it go best with?" />

        <EditText
            android:id="@+id/goesWithEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:ems="10"
            android:hint="...."
            android:inputType="textPersonName" />

        <TextView
            android:id="@+id/whereTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:text="Where did you get it?" />

        <EditText
            android:id="@+id/whereEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:ems="10"
            android:hint="...."
            android:inputType="textPersonName" />

    </LinearLayout>
</ScrollView>

0 голосов
/ 05 ноября 2019

какова ваша позиция EditText. Это в нижней части макета. ALso Установите ширину для match_parent вместо 0 dp

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...