简体   繁体   English

Fragment中的ScrollView在软键盘出现时不滚动

[英]ScrollView in Fragment does not scroll when the soft keyboard shows up

I have a Fragment and there is a ScrollView in that Fragment .我有一个Fragment并且在那个Fragment有一个ScrollView

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:paddingBottom="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/appbar">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.tatar.mobile.widget.CardSelectionView
            android:id="@+id/card_selection_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            app:accountRightTextView1="@string/available"
            app:accountTitleTextView="@string/from"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/line_text_view"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="8dp"
            android:background="@color/gray.light"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/card_selection_view" />

        <Spinner
            android:id="@+id/type_spinner"
            style="@style/spinner"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/line_text_view" />

        <Spinner
            android:id="@+id/company_spinner"
            style="@style/spinner"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/type_spinner" />

        <LinearLayout
            android:id="@+id/dynamic_form_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/company_spinner" />

        <Spinner
            android:id="@+id/installment_spinner"
            style="@style/spinner"
            android:layout_marginTop="8dp"
            android:visibility="invisible"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/dynamic_form_container" />

        <Button
            android:id="@+id/continue_button"
            style="@style/action_button"
            android:layout_marginTop="16dp"
            android:text="@string/continue_button_text"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/installment_spinner" />

    </android.support.constraint.ConstraintLayout>

</ScrollView>

The LinearLayout with the id of dynamic_form_container in that ScrollView contains form input fields which will are populated via a web service call and there might be up to 6-7 input fields depending on the parameters sent to web service.ScrollView中,id 为dynamic_form_containerLinearLayout包含表单输入字段,这些字段将通过 Web 服务调用填充,并且可能有多达 6-7 个输入字段,具体取决于发送到 Web 服务的参数。 So, height of the form is kind of high and that is where the problem starts.所以,表格的高度有点高,这就是问题的开始。 When I try to enter something to an input field, soft keyboard shows up and some of the other input fields stay under the soft keyboard and scrolling is not possible.当我尝试在输入字段中输入内容时,软键盘会出现,而其他一些输入字段则保留在软键盘下方,无法滚动。

I tried to put this to manifest for the Activity of that Fragment but it did not help.我试图将其显示为该FragmentActivity ,但它没有帮助。

android:windowSoftInputMode="adjustResize|stateHidden"

I want to be able to scroll when the soft keyboard shows up.我希望能够在软键盘出现时滚动。 How can I fix that issue ?我该如何解决这个问题?

Any help would be appreciated任何帮助,将不胜感激

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

onCreateView方法中为我工作。

I have found solution for this problem here, include this class in your project.在这里找到了这个问题的解决方案,在你的项目中包含这个类。 And add this following line in onCreate of activity that contains fragment.并在包含片段的活动的 onCreate 中添加以下行。

new KeyboardUtil(this,findViewById(R.id.fragment));

Hello Please refer below code您好 请参考以下代码

this is work for me..这对我来说是工作..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


    </android.support.constraint.ConstraintLayout>
</ScrollView>

AndroidManifest.xml AndroidManifest.xml

  <activity
        android:name=".ui.activities.Activity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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