2016-07-26 44 views
5

在我的應用我使用的是MapView,一個EditTextFloatingActionButton(FAB),我想在單擊EditText當FAB移動鍵盤上方。我發現manifest中的設置android:windowSoftInputMode="adjustResize"與fab的配合良好,但它也調整了我的背景圖,它在調整大小時會產生非常難看的效果。FloatingActionButton鍵盤上方沒有「adjustResize」

這裏是我的佈局:

<CoordinatorLayout> 

    <MapView/> 

    <RelativeLayout> 

     <EditText/> 

     other views ... 

    </RelativeLayout> 

    <FloatingActionButton/> 

    other views ... 

</CoordinatorLayout> 

我如何能得到「adjustResize」的效果,而無需使用任何的想法?或者,也許如何從調整大小,但保持「adjustResize」排除視圖?

預先感謝您

回答

3

一些研究之後,我結束了由根添加GlobalLayoutListener處理鍵盤查看我的佈局,並繪製該根視圖當前可見部分的矩形。
我還將25dp添加到鍵盤的實際高度,因爲某些設備在鍵盤上方有一個建議欄,似乎將其包含在窗口的可見部分。
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)); 
      } 

     } 
    }); 
} 
1

嘗試在佈局XML這是你的根視圖,

android:fitsSystemWindows="true" 

財產

+0

這不起作用 –