ScrollView не прокручивается, когда рост детей увеличивается - PullRequest
0 голосов
/ 28 февраля 2019

У меня есть ScrollView, который содержит 2 фрагмента.Нижний фрагмент имеет 2 EditText просмотров.Когда я вписываю многострочный текст в любой из EditTexts, требования к общей высоте для представлений на экране естественно увеличиваются.Однако экран обрезает все, что выдвигается из-за многострочного ввода текста.ScrollView в этот момент не прокручивается.

Я пробовал некоторые предлагаемые методы для SO, например, не делать ScrollView корневым представлением или добавлять пустое представление в качестве последнего внука представления прокрутки, но пока ни один из них не работал.Это мой XML:

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

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

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:context=".MainActivity">

            <fragment
                android:id="@+id/fragment1"
                android:name="com.example.omar.memegenerator.TopImageFragment"
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="18dp"
                android:layout_marginBottom="18dp"
                tools:layout="@layout/fragment_top_image" />

            <fragment
                android:id="@+id/fragment2"
                android:name="com.example.omar.memegenerator.BottomControlsFragment"
                android:layout_width="match_parent"
                android:layout_height="134dp"
                android:layout_below="@+id/fragment1"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="34dp"
                tools:layout="@layout/fragment_bottom_controls" />

        </RelativeLayout>
    </ScrollView>

</LinearLayout>

1 Ответ

0 голосов
/ 28 февраля 2019

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

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

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

        <fragment
            android:id="@+id/fragment1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <fragment
            android:id="@+id/fragment2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

   </LinearLayout>

</ScrollView>
...