当孩子的身高增加时,ScrollView不会滚动

问题描述 投票:0回答:1

我有一个持有2个碎片的ScrollView。底部片段有2个EditText视图。当我在任一EditTexts中输入多行文本时,屏幕上视图的整体高度要求自然会增加。但是,屏幕会切断由于多行文本输入而被推动的任何内容。 ScrollView不会在该点滚动。

我已经在SO上尝试了一些建议的方法,比如不将ScrollView作为根视图或添加一个空视图作为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>
android android-layout android-linearlayout android-scrollview
1个回答
1
投票

将其用于布局层次结构。我省略了一些属性,但包含的属性是让它工作的关键。

<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>
© www.soinside.com 2019 - 2024. All rights reserved.