hkaraoglu
hkaraoglu

Reputation: 1345

Android keyboard lift tablayout to top?

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 :

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>

Upvotes: 2

Views: 944

Answers (3)

Rehan
Rehan

Reputation: 3285

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>

Upvotes: 0

Alex.F
Alex.F

Reputation: 6201

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.

Upvotes: 0

Mehta
Mehta

Reputation: 1226

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

Upvotes: 0

Related Questions