Scroll View is not working when keyboard is open

╄→尐↘猪︶ㄣ 提交于 2019-12-25 17:04:41

问题


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"

回答1:


use this in ur manifest

android:windowSoftInputMode="adjustPan|stateAlwaysVisible"



回答2:


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



回答3:


Remove Gravity from First child of ScrollView. And Add Following lines in your scrollView

android:scrollbars="vertical"
android:fillViewport="true"



回答4:


Just remove below code from your manifest file in activity tag

android:windowSoftInputMode="adjustPan"



回答5:


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




回答6:


change windowFullscreen true to false it will work!!!

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

Enjoy Coding!!!!




回答7:


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" >


来源:https://stackoverflow.com/questions/27718355/scroll-view-is-not-working-when-keyboard-is-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!