【问题标题】:Android keyboard lift tablayout to top?Android键盘将tablayout提升到顶部?
【发布时间】:2016-06-01 12:07:26
【问题描述】:

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

回到重点,当我打开键盘时,键盘将tablayout提升到顶部?怎么能解决呢?

我尝试了以下方法:

  • android:windowSoftInputMode="adjustPan|adjustResize"
  • android:isScrollContainer="false"

  • android:fitsSystemWindows="true"

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

activity_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 android-layout android-fragments


    【解决方案1】:

    使用android:windowSoftInputMode="adjustPan" 这样tablayout 就不会升到顶部。 Reference

    【讨论】:

      【解决方案2】:

      简短的回答

      你不能设置android:windowSoftInputMode="adjustPan|adjustResize" 这个组合是非法的,如docs所说:

      在任一组中设置多个值(例如,多个“状态...”值)具有未定义的结果

      而只是将其设置为平移android:windowSoftInputMode="adjustPan"

      一些解释

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

      【讨论】:

        【解决方案3】:

        Alex 的回答绝对正确。

        你不能设置android:windowSoftInputMode="adjustPan|adjustResize",这个组合是非法的。

        而只是将其设置为平移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>
        

        【讨论】:

        • 不需要 fitsystemwindow。 True 是默认值。
        • @GabeSechan 是的,默认情况下是这样。但是为了避免在这种情况下产生任何混淆,我宁愿明确定义它,以防它从某个地方继承或无意中丢失。
        猜你喜欢
        • 2019-05-04
        • 1970-01-01
        • 2020-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-15
        相关资源
        最近更新 更多