简体   繁体   中英

layout is not moving up when keyboard is shown

I have a NestedScrollView in my activity with about 7-8 edit texts and I need them move up when keyboard is shown. I'm doing this but it's not working

android:windowSoftInputMode="adjustPan|adjustResize"

activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_login"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:focusableInTouchMode="true"
    tools:context="com.amir_p.cafino.LoginActivity">

    <ImageView
        android:id="@+id/back_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/grayTransparent" />

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:id="@+id/signup_layout"
        android:fillViewport="true"
        android:layout_height="wrap_content"
        android:visibility="gone">

        <LinearLayout
            android:id="@+id/register_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:padding="16dp">

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="36dp"
                android:hint="نام و نام خانوادگی"
                android:textColorHint="@color/white">

                <android.support.design.widget.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:backgroundTint="@color/white" />
            </android.support.design.widget.TextInputLayout>

            [...]
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</RelativeLayout>

try adding android:fillViewport="true" for your scrollview

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:visibility="visible">

and in manifest add:

android:windowSoftInputMode="stateVisible|adjustResize"

you can programetically turn off fillscreen mode:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Fullscreen mode does not resize.

or u can use different theme: android:theme="@android:style/Theme.Black.NoTitleBar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM