我的代码(以及更多):我有一个协调员布局如下
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="280dp"
android:fitsSystemWindows="true"
app:contentScrim="@color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include layout="@layout/top" /> <!-- A RelativeLayout -->
<android.support.v7.widget.Toolbar
android:id="@+id/MyToolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
app:layout_collapseMode="parallax">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- Main content here -->
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
在框架布局中,我正在使用位于底部的编辑文本为自定义视图充气。编辑文本和自定义视图显示正常。
我在清单中定义了android:windowSoftInputMode =“adjustResize | stateHidden”。
我的问题:在点击编辑文本以调出软键盘时,它会重叠下面的内容而不是调整FrameLayout的大小。当软键盘出现时,我无法让FrameLayout调整大小。任何帮助将不胜感激
我试过的事:
试试这个
your_layout.xml
<RelativeLayout
android:fitsSystemWindows="true" > <!-- Crucial! -->
<android.support.design.widget.CoordinatorLayout>
...
<android.support.v7.widget.RecyclerView />
...
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
AndroidManifest.xml中
<activity
android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"> <!-- Crucial! -->
</activity>
这只是设计支持库中的另一个bug,它们似乎是don't plan to fix it any time soon:
确认,但可能不会很快修复。 adjustResize有一些很好的用例,但使用带有CollapsingToolbarLayout的AppBarLayout并不是其中之一。
令人不安的是,在开发设计支持库时,没有人试图用EditText
将CoordinatorLayout
添加到android:windowSoftInputMode="adjustResize"
。
我正在使用它来解决CoordinatorLayout错误
在BottomSheetFragment中的onCreateDialog中
KeyboardUtil(getActivity(), view);
要么
用于活动
new KeyboardUtil(this, findViewById(R.id.fragment_container));
通过使用此Util类
Kotlin版本:https://gist.github.com/agustinsivoplas/6f80233699aebebd512542503ea32682信用:Mikepenz,Agustinsivoplas
我的布局
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<ImageView>
<android.support.v7.widget.Toolbar>
<android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton>
<android.support.design.widget.CoordinatorLayout>
我有同样的问题。我想通了,如果我在例如NestedScrollView
或在FrameLayout
内我会假设处理Scroll本身,CoordinatorLayout
不会adjustResize
/表现你想要的方式。将忽略Manifest中的adjustResize | adjustPan设置。
对我来说,这很难弄明白,因为我自己写了一些(组合)观点,其中包含RelativeLayout
或ScrollViews
等。
如果我只是避免使用RelativeLayouts
或NestedScrollView
之外的其他任何东西来处理视图滚动,它的行为方式,至少我想要它。
但我认为,CoordinatorLayout
中存在一个Bug,或者我们都需要了解更好的行为以避免此类问题...
也许这对于某些人来说很有用......
我的设置是:
嗨我有同样的问题,我只是把
android:windowSoftInputMode="adjustPan"
在yout显示相关活动,键盘现在相应地向上移动视图
adjustResize无法使用
app:layout_behavior="@string/appbar_scrolling_view_behavior"
删除此行:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
KeyboardUtil的缩短版本,将其添加到您的活动中:
getWindow().getDecorView().getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
Rect r = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
rootView.setPadding(0, 0, 0,
activity.getResources().getDisplayMetrics().heightPixels - r.bottom);
}
});
如果在NestedScrollView上使用EditText视图,请不要将CoordinatorLayout用作根布局
<androidx.constraintlayout.widget.ConstraintLayout
android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.appbar.CollapsingToolbarLayout/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView>
<Editext/>
<androidx.core.widget.NestedScrollView/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>