单击ViewPager的editText

问题描述

我有一个片段,其中包含2个fragemnts的ViewPager2。 在第二个子片段中,我有一个recyclerview,其中的视图包含TextView和EditText。

在模拟器中,当我单击EditView时,软键盘保持关闭状态。

在实际设备(Sony xperia XA)中,软键盘没有关闭,但是无论我单击另一个EditText还是它始终专注于第一个编辑文本

我尝试使用android:windowSoftInputMode =“ adjustPan”和android:windowSoftInputMode =“ adjustResize”,但无法解决问题。

我在LinearLayout之外使用DataBinding和ConstraintLayout

<LinearLayout
    android:id="@+id/wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/margin"
    android:focusable="true"
    android:focusableInTouchMode="true"
    tools:context="vn.com.ntn.obee.screens.fragments.exercise.InputQuestionFragment">

    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/margin_medium"
        android:layout_marginEnd="@dimen/margin_medium"
        android:layout_marginBottom="@dimen/margin_medium"
        android:paddingTop="@dimen/margin"
        android:paddingBottom="@dimen/margin_medium"
        app:cardCornerRadius="20dp"
        app:cardElevation="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutQuestion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/question_drawable"
            android:orientation="vertical"
            android:paddingTop="@dimen/margin"
            android:paddingBottom="@dimen/margin"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <vn.com.ntn.obee.screens.views.SelectableTextView
                android:id="@+id/tvQuestion"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:linespacingMultiplier="1.6"
                android:maxHeight="200dp"
                android:paddingStart="@dimen/margin_medium"
                android:paddingEnd="@dimen/margin_medium"
                android:paddingTop="@dimen/margin"
                android:paddingBottom="@dimen/margin_medium"
                android:scrollbars="vertical"
                android:fontFamily="@font/proxima_nova_bold"
                android:textColor="@color/white"
                android:textSize="@dimen/text_size_normal"
                app:htmlText="@{answer.content ?? answerResult.contentExtend}"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <EditText
                android:id="@+id/etAnswer"
                android:layout_width="match_parent"
                android:layout_height="@dimen/size_icon_x5"
                android:hint="@string/enter_your_answer_here"
                android:paddingStart="@dimen/margin_medium"
                android:paddingEnd="@dimen/margin_medium"
                android:paddingBottom="2dp"
                android:layout_marginStart="@dimen/margin_medium"
                android:layout_marginEnd="@dimen/margin_medium"
                android:layout_marginBottom="@dimen/margin_small"
                android:background="@drawable/bg_input_question_edittext"
                android:fontFamily="@font/proxima_nova_bold"
                android:textColor="@color/pink"
                android:textColorHint="#FFC9C9"
                android:textSize="@dimen/text_size_medium"
                android:singleLine="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/tvQuestion"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintVertical_bias="1"/>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.cardview.widget.CardView>

</LinearLayout>

我认为这些日志可能会让我发现问题:

2020-10-12 00:20:43.527 3051-3051/? I/KeyboardViewUtil: KeyboardViewUtil.getKeyboardHeightRatio():128 systemKeyboardHeightRatio:1.000000; userKeyboardHeightRatio:1.000000.
2020-10-12 00:20:43.528 3051-3051/? I/AndroidIME: AbstractIme.onActivate():83 Latinime.onActivate() : EditorInfo = Package = com.nghianguyen.obee_android.debug : Type = Text : Learning = Enable : Suggestion = Show : AutoCorrection = Enable : Microphone = Show : nopersonalizedLearning = disable,IncognitoMode = false
2020-10-12 00:20:43.529 3051-3051/? I/Delight5Facilitator: Delight5Facilitator.initializeforIme():572 initializeforIme() : Locale = [en_US],layout = qwerty
2020-10-12 00:20:43.529 3051-3051/? I/VoiceInputManagerWrapper: VoiceInputManagerWrapper.cancelShutdown():54 cancelShutdown()
2020-10-12 00:20:43.529 3051-3051/? I/VoiceInputManagerWrapper: VoiceInputManagerWrapper.syncLanguagePacks():66 syncLanguagePacks()
2020-10-12 00:20:43.557 3051-6376/? I/SpeechFactory: SpeechRecognitionFactory.maybeScheduleAutopackDownloadForFallback():155 maybeScheduleAutopackDownloadForFallback()
2020-10-12 00:20:43.569 1845-1845/? E/servicemanager: Could not find android.hardware.power.IPower/default in the VINTF manifest.
2020-10-12 00:20:43.596 3051-3051/? I/KeyboardWrapper: KeyboardWrapper.consumeEvent():264 Skip consuming an event as current keyboard is deactivated (state=0,keyboard existence=true)
2020-10-12 00:20:43.669 3051-3051/? W/KeyboardModeManager: KeyboardModeManager.setInputView():359 setInputView() : inputView = com.google.android.apps.inputmethod.libs.framework.core.InputView{cb5f35e V.E...... ......ID 0,0-1080,2022}
2020-10-12 00:20:43.672 3051-3051/? I/ConversationToQueryExtension: ConversationToQueryExtension.isEnabledForHostApp():254 Conv2Query not enabled due to current app [com.nghianguyen.obee_android.debug] not in whitelist
2020-10-12 00:20:43.672 3051-3051/? I/ConversationToQueryExtension: ConversationToQueryExtension.onActivate():165 onActivate() : disabled by unsupported host app
   

解决方法

问题是我使用了过多的约束布局。 我将约束布局用于:

  • ViewPager的子片段。
  • 回收站视图的项目。

我将片段的布局更改为LinearLayout,项目的FrameLayout解决了我的问题。

注意:使用NestedScrollView包装回收器视图剂量可以解决我的问题,但它阻止了我滚动回收器视图