2

I have an activity. This activity's layout has one ViewPager. This viewpager has five fragment by code. And I have five icons at the bottom of screen. They are located in tablayout.

Come to main point, When I open keyboard, the keyboard lift tablayout to top? How can solve it ?

I tried the ways below :

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

  • android:fitsSystemWindows="true"

EDIT : I updated my layout. Any ideas for this problem so far ?

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>
hkaraoglu
  • 1,345
  • 1
  • 15
  • 34

3 Answers3

0

Use android:windowSoftInputMode="adjustPan" so tablayout will not lift to top. Reference

Community
  • 1
  • 1
Mehta
  • 1,228
  • 1
  • 9
  • 27
0

The short answer

You can't set android:windowSoftInputMode="adjustPan|adjustResize" this combination is illegal as stated in the docs:

Setting multiple values in either group — multiple "state..." values, for example — has undefined results

Instead just set it to pan android:windowSoftInputMode="adjustPan"

Some explanation

If the soft keyboard alters your layout it means that either android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustUnspecified" were set. For the latter case the system will deciede automatically if to pan or resize, it will resize if it finds any views that can be scrolled.

Alex.F
  • 5,648
  • 3
  • 39
  • 63
0

Alex's answer is absolutely right.

You can't set android:windowSoftInputMode="adjustPan|adjustResize", this combination is illegal.

Instead just set it to pan android:windowSoftInputMode="adjustPan" it will not move TabLayout to top. But there is one more thing I would like to add. adjustPan and adjustResize work as expected only when you have set android:fitsSystemWindows="true" in your root layout.

So your layout should be

<?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>
Rehan
  • 3,270
  • 5
  • 31
  • 30
  • There's no need for fitssystemwindow. True is the default. – Gabe Sechan Jun 21 '16 at 06:17
  • @GabeSechan Yes it is true by default. But to avoid any confusion in such conditions, I would prefer defining it explicitly in case it is being inherited from somewhere or missed unintentionally. – Rehan Jun 21 '16 at 06:24