1

I have spent a whole day researching on how to achieve this. I have a scrollview, an edittext below it and a button to the right of the edittext.

1) I am trying to move all these contents upwards as the keyboard appears without any of the views overlapping.

This is what I have and this is what happens when edittext is focused. There is this small layer that overlaps my scrollview content

I want to achieve this whatsapp-like content where all content moves upwards but edittext and button do not overlap content above

I have tried different solutions like margin, padding, windowsoftinputMode, changing my layout in different ways but I couldn't still achieve this. Please Help me! This is my code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
    android:id="@+id/detailsToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorToolbar"
    android:elevation="4dp"
    android:theme="@style/Toolbar_iconTheme" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/detailsToolbar"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

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

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

                <ImageView
                    android:id="@+id/displayPicture"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:maxHeight="100dp"
                    android:maxWidth="80dp"
                    android:minHeight="80dp"
                    android:minWidth="70dp"
                    android:padding="4dp"
                    android:src="@mipmap/ic_launcher_round" />

                <TextView
                    android:id="@+id/name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_toRightOf="@+id/displayPicture"
                    android:paddingLeft="4dp"
                    android:paddingTop="4dp"
                    android:text="ProfileName"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                    android:textColorHighlight="@android:color/holo_blue_dark"
                    android:textSize="16sp" />

                <TextView
                    android:id="@+id/post"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/name"
                    android:layout_toRightOf="@+id/displayPicture"
                    android:padding="4dp" />

                <TextView
                    android:id="@+id/commentsline"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/displayPicture"
                    android:background="@android:color/darker_gray"
                    android:padding="4dp"
                    android:text="comments"
                    android:textAlignment="center" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/commentsListView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/commentsline" />

            </RelativeLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:orientation="horizontal">

    <RelativeLayout
        android:id="@+id/messageText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="32dp"
            android:background="@drawable/rounded_corners"
            android:scrollbars="vertical" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@android:drawable/ic_menu_send" />

    </RelativeLayout>
</LinearLayout>

and Manifest:

<activity
        android:name=".DetailsActivity"
        android:windowSoftInputMode="adjustResize"/>
  • You need to put your entire layout in a "container" like when you add a Snackbar notification. When you add a snackbar notification you are required to designate a container and put elements you want the Snackbar to move up when it appears into the container. This is done with a Coordinator layout (aka FrameLayout). Snackbar: https://developer.android.com/training/snackbar/showing.html Another source for your questions people seem to like: https://stackoverflow.com/a/1964928/4167644 – Frank B. Jul 23 '17 at 13:59
  • 1
    https://stackoverflow.com/questions/16411056/how-to-adjust-layout-when-soft-keyboard-appears , This is the best solution for this issue. hope its helps to your stuff. – InsaneCat Jul 24 '17 at 05:53

1 Answers1

0

make your layout like this

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu_linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/detailsToolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/Toolbar_iconTheme" />


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

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

            <ImageView
                android:id="@+id/displayPicture"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxHeight="100dp"
                android:maxWidth="80dp"
                android:minHeight="80dp"
                android:minWidth="70dp"
                android:padding="4dp"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_toRightOf="@+id/displayPicture"
                android:paddingLeft="4dp"
                android:paddingTop="4dp"
                android:text="ProfileName"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColorHighlight="@android:color/holo_blue_dark"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/post"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/name"
                android:layout_toRightOf="@+id/displayPicture"
                android:padding="4dp" />

            <TextView
                android:id="@+id/commentsline"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/displayPicture"
                android:background="@android:color/darker_gray"
                android:padding="4dp"
                android:text="comments"
                android:textAlignment="center" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/commentsListView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/commentsline" />

        </RelativeLayout>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/messageText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="32dp"
                android:background="@drawable/ic_calender"
                android:scrollbars="vertical" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:src="@android:drawable/ic_menu_send" />

        </RelativeLayout>
    </LinearLayout>
</LinearLayout>
</ScrollView>

and in your manifest file

        <activity
        android:name=".Activity"
        android:theme="@style/SeachTheme"
        android:windowSoftInputMode="adjustResize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163