Android 安卓键盘提升到顶部?

Android 安卓键盘提升到顶部?,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我有一个活动。此活动的布局有一个ViewPager。此viewpager有五个代码片段。我在屏幕底部有五个图标。它们位于tablayout 说到要点,当我打开键盘时,键盘会将工作台提升到顶部吗?如何解决呢 我尝试了以下方法: android:WindowsOfInputMode=“adjustPan | adjustResize” android:isScrollContainer=“false” android:fitsSystemWindows=“true” 编辑: 我更新了布局。到目前

我有一个活动。此活动的布局有一个ViewPager。此viewpager有五个代码片段。我在屏幕底部有五个图标。它们位于tablayout

说到要点,当我打开键盘时,键盘会将工作台提升到顶部吗?如何解决呢

我尝试了以下方法:

  • android:WindowsOfInputMode=“adjustPan | adjustResize”
  • android:isScrollContainer=“false”

  • android:fitsSystemWindows=“true”

编辑: 我更新了布局。到目前为止对这个问题有什么想法吗

活动\u home.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activityRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/toolbar" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.DrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/DrawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appBarLayout">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:fillViewport="true"
            android:isScrollContainer="true"
            android:layout_weight="1">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:transitionGroup="false"
                android:layout_weight="1" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                style="@style/MyCustomTabLayout"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:background="@drawable/bottom_bar_background"
                app:tabMode="fixed"
                app:tabPaddingEnd="0dp"
                app:tabPaddingStart="0dp"
                app:tabTextAppearance="@style/MyCustomTabText" />
        </LinearLayout>

        </ScrollView>
        <include
            layout="@layout/navigation_drawer_menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/tabs"
            android:layout_gravity="start"
            android:layout_marginBottom="?actionBarSize" />
    </android.support.v4.widget.DrawerLayout>


</RelativeLayout>

使用android:WindowsofInputMode=“adjustPan”使表格布局不会上升到顶部

简短的回答 您无法设置android:WindowsOfInputMode=“adjustPan | adjustResize” 如以下文件所述,这种组合是非法的:

在任一组中设置多个值(例如多个“状态…”值)会产生未定义的结果

相反,只需将其设置为pan
android:windowSoftInputMode=“adjustPan”

一些解释
如果软键盘改变您的布局,则意味着设置了
android:windowSoftInputMode=“adjustResize”
android:windowSoftInputMode=“adjustUnspecified”
。对于后一种情况,系统将自动决定是否平移或调整大小,如果找到任何可以滚动的视图,系统将调整大小。

Alex的答案绝对正确

您无法设置android:WindowsOfInputMode=“adjustPan | adjustResize”,这种组合是非法的

相反,只需将其设置为pan
android:windowSoftInputMode=“adjustPan”
它将不会将
TabLayout
移动到顶部。但我想补充一点adjustPanadjustResize仅当您在根布局中设置了
android:fitsSystemWindows=“true”
时才能按预期工作

所以你的布局应该是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activityRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    // Your Layout

</RelativeLayout>

//你的布局

无需安装fitssystemwindow。True是默认值。@Gabeschen是,默认值为True。但为了避免在这种情况下产生任何混乱,我更愿意明确地定义它,以防它从某处继承或无意中丢失。