键盘弹出时LinearLayout无法滚动

3
我遇到了ScrollView的问题。当键盘出现时,ScrollView没有滚动到视图的底部。
这是我的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:text="Add Member"
        android:textColor="#FFF"
        android:textSize="@dimen/heading_text_size"
        android:background="@color/heading"
        android:gravity="center"
        android:padding="10dp"
        android:layout_height="?attr/actionBarSize"/>

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

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

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

                <EditText
                    android:id="@+id/search_member_number"
                    android:layout_width="match_parent"
                    android:hint="Enter mobile number"
                    android:layout_weight="3"
                    android:inputType="phone"
                    android:layout_marginLeft="10dp"
                    android:layout_gravity="center"
                    android:layout_height="wrap_content"/>

                <Button
                    android:id="@+id/searchExistingUserButton"
                    android:layout_width="wrap_content"
                    android:layout_gravity="center"
                    android:text="Search"
                    android:textAllCaps="false"
                    android:background="#FF9800"
                    android:layout_margin="10dp"
                    android:layout_height="wrap_content"/>
            </LinearLayout>

            <EditText
                android:id="@+id/txtUsername"
                android:layout_width="match_parent"
                android:layout_margin="10dp"
                android:hint="Enter member name"
                android:layout_height="wrap_content"/>

            <EditText
                android:id="@+id/txtAddress"
                android:layout_width="match_parent"
                android:hint="Address"
                android:layout_margin="10dp"
                android:layout_height="wrap_content"/>

            <EditText
                android:id="@+id/txtEmail"
                android:layout_width="match_parent"
                android:hint="Email"
                android:layout_margin="10dp"
                android:layout_height="wrap_content"/>

            <EditText
                android:id="@+id/txtContact"
                android:layout_width="match_parent"
                android:hint="Mobile No"
                android:inputType="phone"
                android:layout_margin="10dp"
                android:layout_height="wrap_content"/>

            <EditText
                android:id="@+id/txtReferredBy"
                android:layout_width="match_parent"
                android:hint="Referred by"
                android:layout_margin="10dp"
                android:layout_height="wrap_content"/>

            <AutoCompleteTextView
                android:id="@+id/txtKittyGroups"
                android:layout_width="match_parent"
                android:hint="Enter kitty group name"
                android:layout_margin="10dp"
                android:layout_weight="8"
                android:layout_gravity="center"
                android:textSize="@dimen/admin_setup_buttons_text_size"
                android:textColor="#000"
                android:layout_height="wrap_content"/>

            <EditText
                android:id="@+id/txtRepeat"
                android:layout_width="match_parent"
                android:hint="Enter repeat number"
                android:layout_margin="10dp"
                android:inputType="number"
                android:layout_height="wrap_content"/>

            <Button
                android:id="@+id/createUserButton"
                android:layout_width="wrap_content"
                android:layout_gravity="right"
                android:text="Create Member"
                android:textAllCaps="false"
                android:background="#BBDEFB"
                android:layout_margin="10dp"
                android:padding="10dp"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

我在stackoverflow上看到了几篇帖子,但不幸的是没有一个有效。可能的解决方案是什么?
提前感谢。
3个回答

0
请在你的布局中使用以下代码:

android:layout_marginBottom="16dp"

0

你需要添加<Space/>

 android:layout_height="100dp"

给定你想要的静态高度。

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:text="Add Member"
            android:textColor="#FFF"
            android:textSize="@dimen/heading_text_size"
            android:background="@color/heading"
            android:gravity="center"
            android:padding="10dp"
            android:layout_height="?attr/actionBarSize"/>

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

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

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

                    <EditText
                        android:id="@+id/search_member_number"
                        android:layout_width="match_parent"
                        android:hint="Enter mobile number"
                        android:layout_weight="3"
                        android:inputType="phone"
                        android:layout_marginLeft="10dp"
                        android:layout_gravity="center"
                        android:layout_height="wrap_content"/>

                    <Button
                        android:id="@+id/searchExistingUserButton"
                        android:layout_width="wrap_content"
                        android:layout_gravity="center"
                        android:text="Search"
                        android:textAllCaps="false"
                        android:background="#FF9800"
                        android:layout_margin="10dp"
                        android:layout_height="wrap_content"/>
                </LinearLayout>

                <EditText
                    android:id="@+id/txtUsername"
                    android:layout_width="match_parent"
                    android:layout_margin="10dp"
                    android:hint="Enter member name"
                    android:layout_height="wrap_content"/>

                <EditText
                    android:id="@+id/txtAddress"
                    android:layout_width="match_parent"
                    android:hint="Address"
                    android:layout_margin="10dp"
                    android:layout_height="wrap_content"/>

                <EditText
                    android:id="@+id/txtEmail"
                    android:layout_width="match_parent"
                    android:hint="Email"
                    android:layout_margin="10dp"
                    android:layout_height="wrap_content"/>

                <EditText
                    android:id="@+id/txtContact"
                    android:layout_width="match_parent"
                    android:hint="Mobile No"
                    android:inputType="phone"
                    android:layout_margin="10dp"
                    android:layout_height="wrap_content"/>

                <EditText
                    android:id="@+id/txtReferredBy"
                    android:layout_width="match_parent"
                    android:hint="Referred by"
                    android:layout_margin="10dp"
                    android:layout_height="wrap_content"/>

                <AutoCompleteTextView
                    android:id="@+id/txtKittyGroups"
                    android:layout_width="match_parent"
                    android:hint="Enter kitty group name"
                    android:layout_margin="10dp"
                    android:layout_weight="8"
                    android:layout_gravity="center"
                    android:textSize="@dimen/admin_setup_buttons_text_size"
                    android:textColor="#000"
                    android:layout_height="wrap_content"/>

                <EditText
                    android:id="@+id/txtRepeat"
                    android:layout_width="match_parent"
                    android:hint="Enter repeat number"
                    android:layout_margin="10dp"
                    android:inputType="number"
                    android:layout_height="wrap_content"/>

                <Button
                    android:id="@+id/createUserButton"
                    android:layout_width="wrap_content"
                    android:layout_gravity="right"
                    android:text="Create Member"
                    android:textAllCaps="false"
                    android:background="#BBDEFB"
                    android:layout_margin="10dp"
                    android:padding="10dp"
                    android:layout_height="wrap_content"/>
                <Space
                    android:layout_width="match_parent"
                    android:layout_height="100dp" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout></LinearLayout>

0

我认为问题是由 adjustPan 引起的。其中 adjustPan 不会调整窗口大小,而是平移视图,以便软键盘永远不会遮挡焦点所在的内容。

将此添加到您的 AndroidManifest.xml 中。这可能会解决问题。

示例:

<activity android:name="YourActivity" 
          android:windowSoftInputMode="adjustResize" />

尝试过了。不幸的是,这并没有解决问题。 - TechBee
当键盘弹出时,当您尝试滚动到底部时,实际上会发生什么?它会卡在特定的高度吗?您是否尝试从底部偏移布局并查看其是否有效? - Galib Imtiaz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接