键盘出现时,LinearLayout不滚动

时间:2018-01-27 09:40:25

标签: android android-layout

我遇到了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 :(得分:0)

我认为问题是由adjustPan引起的。调整Pan不会调整窗口的大小,它会平移视图,这样任何具有焦点的东西都不会被软键盘遮挡。

将此添加到AndroidManifest.xml。这可能会成功。

示例:

UTF

答案 1 :(得分:0)

在布局中使用它:

android:layout_marginBottom="16dp"

答案 2 :(得分: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>