Search code examples
androidandroid-recyclerviewresizechatandroid-softkeyboard

How resize layout when keyboard shown


Good morning to everybody, I have a little problem about resizing of layout when keyboard is shown.

enter image description here

enter image description here

In manifest I have adjustResize and also I tried to use adjustPan but I have problem with scrolling of recyclerview.

My layout code is:

<LinearLayout
android:id="@+id/layoutGeneralHome"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragments.fragment_home">

<LinearLayout
    android:id="@+id/layoutRecycler"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.9">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/listChatGeneral"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.10"
    android:orientation="horizontal">

    <LinearLayout

        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.75"
        android:orientation="vertical">

        <EditText
            android:id="@+id/edtMessage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:hint="Scrivi messaggio"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25">

        <Button
            android:id="@+id/btnSend"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="INVIA"
            android:textSize="18sp"/>

    </LinearLayout>

</LinearLayout>
</LinearLayout>

Thanks who could help me


Solution

  • You have no need to add scrollview, Using Relative layout U can achieve Screen like u want. I have add Relative layout and Code like below.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="vertical">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/listChatGeneral"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/llSendView" />
    
        <LinearLayout
            android:id="@+id/llSendView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center_vertical"
            android:orientation="horizontal">
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.75"
                android:orientation="vertical">
    
                <EditText
                    android:id="@+id/edtMessage"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Scrivi messaggio" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.25">
    
                <Button
                    android:id="@+id/btnSend"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="INVIA"
                    android:textSize="18sp" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>