2017-04-24 30 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 活动 的主窗口如何与包含屏幕上的软键盘的窗口交互。该属性的 设置会影响两件事情:软键盘的状态 - 无论是隐藏的还是可见的 - 当活动成为用户关注的焦点时, 。对活动 主窗口所作的调整 - 是否缩小尺寸以便为软键盘 留出空间,或者其内容是否平移以使当前焦点可见 当部分窗口被软键盘覆盖时。