Is there a way we can jump just the edittext not the complete layout when keyboard opens?

134 views Asked by At

I am trying with bottom sheet dialog fragment, but whenever the keyboard opens the layout also jumps in fragment like recyclerview, already tried with adjustPan and adjustNothing but no success.

Can anyone please help me out ( Need something similar to tiktok UI comments section )

  • Tried this already [ https://stackoverflow.com/questions/55788594/remaking-tiktoks-comments-ui-sticky-edittext-at-the-bottom ] but its not working in my case

Some xml snippet which I tried yet

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/no_of_comments"
            android:layout_width="match_parent"
            android:layout_height="36dp"
            android:gravity="center_vertical|center_horizontal"
            android:text="30.8k comments"
            android:textColor="@color/graycolor" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="300dp">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/comments_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </ScrollView>
        
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_gravity="bottom"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/top_gray_line"
            android:hint="Leave a comment"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:textSize="12sp" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:alpha="0.3"
            android:background="@android:color/white"
            android:hapticFeedbackEnabled="true"
            android:src="@drawable/ic_send_pink" />

    </RelativeLayout>

</FrameLayout>
1

There are 1 answers

2
Try this On

You can try something like following: activity_main:

<RelativeLayout 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:padding="20dp"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="126dp"
        android:ems="10"
        android:hint="This is EditText"
        android:gravity="center" >
    </EditText>

</RelativeLayout>

AndroidManifest:

<activity android:name=".MainActivity"
            android:windowSoftInputMode="stateVisible|adjustPan">
            <intent-filter>
                ...
            </intent-filter>
</activity>

For output like: enter image description here