我希望能够在不改变布局大小的情况下打开键盘。我不想使用
因此,我将我的布局(
有什么办法可以解决这个问题吗?为什么每第三次打开键盘时布局会重新调整大小?
adjustNothing
,因为我需要我的底部视图之一随着键盘升起。我也不想使用adjustPan
,因为它会将整个布局抬离屏幕,这有点丑陋。因此,我将我的布局(
ConstraintLayout
)包装在一个ScrollView
中,如下所示:<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.mypackage.MyViewModel"/>
</data>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<!-- I don't want anything in this ConstraintLayout to move or resize when I open the keyboard, hence why I wrapped it in a ScrollView. -->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/scene_container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/scene"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:background="@color/black"
android:scaleType="fitCenter"
android:src="@drawable/grumpy"/>
</FrameLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent=".7"/>
<View
android:id="@+id/status_bar"
android:layout_width="0dp"
android:layout_height="48dp"
android:background="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guideline"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="48dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/status_bar"/>
</android.support.constraint.ConstraintLayout>
</ScrollView>
<!-- The bottom sheet contains a 48dp high peekable area (a bar with an EditText) that I need to raise with the keyboard. -->
<include
android:id="@+id/bottom_sheet"
layout="@layout/bottom_sheet"
app:viewModel="@{viewModel}"/>
</android.support.design.widget.CoordinatorLayout>
对于前两次打开键盘,这个功能表现得很好。以下是我遇到的奇怪问题。每第三次打开键盘时,我的布局都会重新调整大小,并挤在一起,就好像ScrollView
不存在一样。这种情况每第三次打开键盘都会如此发生:
1) Open keyboard. Layout remains same size.
Close keyboard.
2) Open keyboard. Layout remains same size.
Close keyboard.
3) Open keyboard. *LAYOUT RESIZES/SQUISHES TOGETHER!*
Close keyboard.
The above cycle repeats as I continue to open/close the keyboard.
有什么办法可以解决这个问题吗?为什么每第三次打开键盘时布局会重新调整大小?