Lukas
Lukas

Reputation: 829

Complete Layout moves upwards if Soft Keyboard is shown

is there a way to just move a certain layout above the keyboard and let the rest untouched? I have tried using android:windowSoftInputMode="stateVisible|adjustResize" and using a scrollview, but neither of them worked.

default layout

This is how it looks, if the keyboard is shown, but I just need to move the comment layout on the bottom above the keyboard and let the rest as it was.

resized layout

My code looks like shown below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/colorWhite"
          android:orientation="vertical">

<ScrollView
        android:layout_width="match_parent"
        android:layout_weight="20"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView">

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorTransparent" android:id="@+id/toolbar_comments">

            <ImageButton
                    android:layout_width="50dp"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_arrow_back"
                    android:tint="@android:color/black"
                    android:background="@color/colorTransparent"   android:id="@+id/back_btn_comments"/>

            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textAlignment="center"
                    android:gravity="center"
                    android:textSize="20sp"
                    android:textColor="@android:color/black"
                    android:text="Kommentare"/>
            <View
                    android:layout_width="match_parent"
                    android:layout_height="0.5dp"
                    android:layout_alignParentBottom="true"
                    android:background="@color/colorFont"/>

        </RelativeLayout>

        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/comments_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/toolbar_comments"
                android:layout_marginTop="5dp">

        </androidx.recyclerview.widget.RecyclerView>
    </RelativeLayout>
</ScrollView>

<include
        layout="@layout/message_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:layout_marginTop="5dp"/>
</LinearLayout>

Thanks for your help!

Upvotes: 1

Views: 84

Answers (1)

Jignesh Mayani
Jignesh Mayani

Reputation: 7193

Try below code, It works for me

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorBackGround"
            android:orientation="vertical">

           //toolbar code here

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:isScrollContainer="true"
                android:layout_weight="1">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerMessages"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clipToPadding="false"
                    android:padding="@dimen/_10sdp" />

            </RelativeLayout>


           //comment layout code here

        </LinearLayout>

and add below type in manifest

android:windowSoftInputMode="adjustUnspecified"

Upvotes: 1

Related Questions