У меня есть scrollView и ConstraintLayout в детстве. Внутри constraintLayout у меня есть как минимум 2 editTexts. Мой макет:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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/colorWhite"
android:descendantFocusability="afterDescendants"
android:fitsSystemWindows="true"
android:focusable="false">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/status_bar_height"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:id="@+id/sendScrollView"
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
android:isScrollContainer="false"
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="@id/nextButton"
app:layout_constraintEnd_toEndOf="@id/endGuideline"
app:layout_constraintStart_toStartOf="@id/startGuideline"
app:layout_constraintTop_toBottomOf="@id/toolbar">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/exchangeCardView"
android:layout_width="@dimen/currency_switch_width"
android:layout_height="@dimen/currency_switch_height"
android:layout_marginTop="@dimen/default_margin"
android:padding="2dp"
app:cardCornerRadius="20dp"
app:cardElevation="@dimen/elevation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ExchangeCurrencyView
android:id="@+id/exchangeSwitchView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.cardview.widget.CardView>
<EditText
android:id="@+id/amountEditText"
style="@style/EditTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_x2"
android:autofillHints=""
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:inputType="number|numberDecimal"
android:maxLines="1"
android:minWidth="40dp"
android:singleLine="true"
android:textSize="50sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/exchangeCardView" />
<TextView
android:id="@+id/amountTextView"
style="@style/AmountTextViewStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/amountEditText" />
<TextView
android:id="@+id/balanceTextView"
style="@style/AddressTextViewStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/amountTextView" />
<SidedEditTextView
android:id="@+id/walletAddressEditTextView"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_marginTop="@dimen/default_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/balanceTextView" />
<TextView
android:id="@+id/miningFeesTextView"
style="@style/AddressTextViewStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:gravity="center"
android:textColor="@color/feesColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/walletAddressEditTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<Button
android:id="@+id/nextButton"
style="@style/RoundButtonStyle"
android:layout_width="0dp"
android:layout_height="@dimen/button_height"
android:layout_marginBottom="@dimen/default_margin_x1"
android:enabled="false"
android:gravity="center"
android:stateListAnimator="@null"
android:text="@string/send"
android:translationZ="@dimen/elevation"
app:elevation="@dimen/elevation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/endGuideline"
app:layout_constraintStart_toStartOf="@id/startGuideline"
app:layout_constraintTop_toBottomOf="@id/sendScrollView" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/startGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.06" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/endGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.94" />
Я хотел бы прокрутить до конца моего scrollView, чтобы увидеть все входы над кнопкой.
Я использовал KeyboardHeightProvider для чтобы сделать это, и это работает:
override fun onHeightChanged(height: Int) {
getScrollView()?.let {
when (height) {
0 -> {
it.post {
it.scrollTo(0, 0)
onHide()
}
}
else -> {
it.post {
it.fullScroll(View.FOCUS_DOWN)
}
}
}
}
}
Но с этим фрагментом клавиатура мигает на экране, и я получаю предупреждение IInputConnectionWrapper.
Я пробовал много других решений, таких как добавление AdjustPan или AdjustResize, но Ни один не работал.
android:windowSoftInputMode="adjustResize"
android:fitsSystemWindows="true"
Кроме того, я использовал это:
val rootView = view?.findViewById<ViewGroup>(android.R.id.content)?.getChildAt(0)
rootView?.let {
it.viewTreeObserver.addOnGlobalLayoutListener {
val diff = it.rootView.height - it.height
if (diff > dpToPx(context!!, 200F)) {
sendScrollView.fullScroll(View.FOCUS_DOWN)
} else {
sendScrollView.fullScroll(View.FOCUS_UP)
}
}
}
Есть идеи?