Scroll View is not working when keyboard is open

2019-09-20 15:03发布

I am using ScrollView for scrolling my layout.But not working in Fragment class when keyboard is open. I am novice with Fragments.

Here is my XML Code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/settingLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash_bg" >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <ImageView
            android:id="@+id/tree_iv_userSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/tree_transparent" />
        <ScrollView
            android:id="@+id/sv_rl_user_settings"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:isScrollContainer="true" >

            <RelativeLayout
                android:id="@+id/main_rl_user_settings"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center" >

                <ImageView
                    android:id="@+id/image1"
                    android:layout_width="90dp"
                    android:layout_height="110dp"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="30dp"
                    android:src="@drawable/frame_large" />

                <TextView
                    android:id="@+id/changepassword"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/image1"
                    android:layout_marginLeft="20dp"
                    android:background="@android:color/transparent"
                    android:hint="CHANGE PASSWORD"
                    android:singleLine="true"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="@android:color/black"
                    android:textColorHint="@android:color/black" />

                <EditText
                    android:id="@+id/editname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/changepassword"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="15dp"
                    android:background="@android:color/transparent"
                    android:hint="EDIT NAME"
                    android:maxLength="20"
                    android:singleLine="true"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColorHint="@android:color/black" />

                <EditText
                    android:id="@+id/editphoneno"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/editname"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="15dp"
                    android:background="@android:color/transparent"
                    android:hint="EDIT PHONE NUMBER"
                    android:maxLength="15"
                    android:numeric="integer"
                    android:singleLine="true"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColorHint="@android:color/black" />

                <TextView
                    android:id="@+id/edittype"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/editphoneno"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="15dp"
                    android:background="@android:color/transparent"
                    android:singleLine="true"
                    android:text="EDIT TYPE"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="@android:color/black" />

                <TextView
                    android:id="@+id/notification"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/edittype"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="15dp"
                    android:background="@android:color/transparent"
                    android:singleLine="true"
                    android:text="NOTIFICATION"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="@android:color/black" />

                <Button
                    android:id="@+id/togNot"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/save"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="20dp"
                    android:background="@drawable/on_button" />

                <TextView
                    android:id="@+id/save"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/notification"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="30dp"
                    android:background="@android:color/transparent"
                    android:text="SAVE "
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="@android:color/black"
                    android:textSize="40dp" />

                <ProgressBar
                    android:id="@+id/progressBar1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/image1"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="27dp" />
            </RelativeLayout>
        </ScrollView>

        <RelativeLayout
            android:id="@+id/bottomRelay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="7.5dp"
            android:background="@android:color/transparent"
            android:visibility="gone" >

            <TextView
                android:id="@+id/Upload"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Upload Photo"
                android:textColor="#8F8F8F"
                android:textSize="20dp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/border1"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@id/Upload"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#939393" />

            <TextView
                android:id="@+id/choose_existing"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/border1"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="1dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Library"
                android:textColor="#007AFF"
                android:textSize="20dp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/border2"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@id/choose_existing"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#939393" />

            <TextView
                android:id="@+id/Camera"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/border2"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="1dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Camera"
                android:textColor="#007AFF"
                android:textSize="20dp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/border3"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@id/Camera"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#939393" />

            <TextView
                android:id="@+id/cancel"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/border3"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="20dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Cancel"
                android:textColor="#007AFF"
                android:textSize="20dp"
                android:textStyle="bold" />
        </RelativeLayout>

        <ImageView
            android:id="@+id/dropimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/drop_down"
            android:visibility="invisible" />
    </RelativeLayout>

</RelativeLayout>

Manifest code of that Activity:

android:name="com.treeapp.header.Header"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:theme="@android:style/Theme.NoTitleBar"

7条回答
祖国的老花朵
2楼-- · 2019-09-20 15:18

Just remove below code from your manifest file in activity tag

android:windowSoftInputMode="adjustPan"
查看更多
爷、活的狠高调
3楼-- · 2019-09-20 15:19

change windowFullscreen true to false it will work!!!

<item name="android:windowFullscreen">false</item>

Enjoy Coding!!!!

查看更多
贪生不怕死
4楼-- · 2019-09-20 15:21

ScrollView should contain LinearLayout as the inner childView, you could add a LinearLayout out of the RelativeLayout like this:

<ScrollView
        android:id="@+id/sv_rl_user_settings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:isScrollContainer="true" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        <RelativeLayout
            android:id="@+id/main_rl_user_settings"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center" >
查看更多
何必那么认真
5楼-- · 2019-09-20 15:22

use this in ur manifest

android:windowSoftInputMode="adjustPan|stateAlwaysVisible"
查看更多
小情绪 Triste *
6楼-- · 2019-09-20 15:24

I am sugesting you to use LinearLayout instead of relative layout with vertical orientation layout in which you are using scroll and to hide your keyboard you can use the below code when you scroll the view just use

ScrollView anyname;
anyname =(ScrollView)rootView.findViewById(R.id.sv_rl_user_settings);
anyname.setparentView.setOnTouchListener(this);



@Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager) getactivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getactivity().getWindow().getCurrentFocus().getWindowToken(), 0);
            return false;

        }
in your fragment java file i hope it will work
查看更多
男人必须洒脱
7楼-- · 2019-09-20 15:37

Use this in your manifest android:windowSoftInputMode="adjustResize|stateAlwaysVisible"

查看更多
登录 后发表回答