Dav*_*ssi 5 keyboard android floating-action-button
在我的应用程序中,我使用a MapView,an EditText和a FloatingActionButton(fab),我希望fab在EditText点击时移动到键盘上方.我发现android:windowSoftInputMode="adjustResize"在manifest工作中很好地设置了它,但它也调整了我在背景中的地图的大小,并且它在调整大小时给出了非常难看的效果.
这是我的布局:
<CoordinatorLayout>
<MapView/>
<RelativeLayout>
<EditText/>
other views ...
</RelativeLayout>
<FloatingActionButton/>
other views ...
</CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
关于如何在不使用它的情况下获得"adjustResize"效果的任何想法?或者也许如何从调整大小中排除视图但保持"adjustResize"?
先感谢您
经过一些研究,我最后通过GlobalLayoutListener在布局的根视图上添加一个处理keyBoard ,并绘制了一个矩形的根视图的当前可见部分.
我还在键盘的实际高度上添加了25dp,因为有些设备在键盘上方有一个建议栏,似乎包含在窗口的可见部分中.当a 扩展时
,if条件是防止任何翻译bottomSheet.
private void handleKeyBoardApparition() {
root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
root.getWindowVisibleDisplayFrame(r);
int heightDiff = root.getBottom() - r.bottom;
int suggestionsBarHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,25,getActivity().getResources().getDisplayMetrics());
if(!bottomSheetIsVisible){
fabSearch.setTranslationY(-(heightDiff + suggestionsBarHeight));
}
}
});
}
Run Code Online (Sandbox Code Playgroud)