2017-04-24 72 views
0

當對焦EditText並且軟鍵盤被打開時,它會在我的NavigationView佈局(參見屏幕截圖)中推動我的headerLayout。 我假設它與android:fitsSystemWindows="true"有關nav_header_navigation.xmlRelativeLayout。如果我刪除它,內容不會被推高,但它不像以前那樣正確地適合屏幕。 有什麼辦法解決這個問題?軟鍵盤將NavigationView的headerLayout向上推

  • 1截圖:關閉鍵盤,與 android:fitsSystemWindows="true"
  • 第二截圖:打開鍵盤,用android:fitsSystemWindows="true"
  • 3截圖:打開鍵盤,無需android:fitsSystemWindows="true"

代碼:

<!-- activity.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <LinearLayout ../> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:itemTextColor="@color/navigation" 
     app:itemIconTint="@color/navigation" 
     app:app="@layout/nav_header_navigation" 
     app:menu="@menu/navigation_drawer" /> 
</android.support.v4.widget.DrawerLayout> 


<!-- nav_header_navigation.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/nav_header_height" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

    <ImageView 
     android:id="@+id/nav_header_navigation_avatar" 
     android:scaleType="centerCrop" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="@dimen/margin_big" 
     android:layout_marginTop="@dimen/margin_big" 
     android:src="@drawable/ic_edit_white_24dp" 
     android:layout_alignParentRight="true"/> 

    <LinearLayout .../> 

</RelativeLayout> 

enter image description hereenter image description hereenter image description here

+0

你是否將'android:windowSoftInputMode =「adjustResize」'應用於你的活動? – azizbekian

+0

同樣的結果。 'adjustPan'就是一種解決方案,儘管它並不完美,因爲菜單根本看不到。 – Chris

+0

您是否找到解決方案?我正在處理同樣的問題 – dumazy

回答

0

documentation

安卓windowSoftInputMode 活動 的主窗口如何與包含屏幕上的軟鍵盤的窗口交互。該屬性的 設置會影響兩件事情:軟鍵盤的狀態 - 無論是隱藏的還是可見的 - 當活動成爲用戶關注的焦點時, 。對活動 主窗口所作的調整 - 是否縮小尺寸以便爲軟鍵盤 留出空間,或者其內容是否平移以使當前焦點可見 當部分窗口被軟鍵盤覆蓋時。