4

I'm trying to achieve the following view in a chat app. There are basically two states one with the soft touch keyboard showing and one without.

So this is my initial state without the keyboard showing.

enter image description here

This is what happens when the keyboard shows up.

enter image description here

This is what i'm trying to achieve.

enter image description here

Note I'm current using "adjust-resize" as the windowSoftInputMode. I know using "adjust-pan" will fix the issue, but with "adjust-pan" there are 2 problems :

  1. The toolbar also moves up making space for the edit-text and keyboard.
  2. The editText gets partly covered by the keyboard.

A layout experts help is needed here! Thanks in advance.

Edit:

This is what my XML looks like:

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

    <LinearLayout
        android:id="@+id/view_group_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimaryDark"
            android:elevation="4dip" >

            <!-- Toolbar stuff -->

        </android.support.v7.widget.Toolbar>

    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_bar"
        android:layout_below="@+id/view_group_toolbar"
        android:orientation="vertical">

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

            <include
                layout="@layout/layout_that_covers_60%_of_the_screen (This is not my actual layout name :/ using it for understandability)"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/view_group_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.4"
            android:gravity="center_vertical">

            <include
                layout="@layout/layout_that_covers_40%_of_the_screen"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/bottom_bar"
        android:layout_width="match_parent"
        android:layout_height="60dip"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:padding="8dip" > 
            <!-- This is where my edit text resides -->

    </RelativeLayout> 

</RelativeLayout>
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Tejas
  • 437
  • 5
  • 12
  • well structured question can you post your xml or root tag of it? – Charuක Jan 28 '17 at 05:43
  • post your code. – Kishore Jethava Jan 28 '17 at 05:46
  • Hey guys thanks for your quick reply, I've edited the question to include my XML. It's is a rough sketch of what my layout looks like. – Tejas Jan 28 '17 at 05:53
  • try this [answer](http://stackoverflow.com/questions/27248555/soft-keyboard-pushing-up-layout-or-hidding-action-bar) – Kishore Jethava Jan 28 '17 at 06:07
  • @kishorejethava Setting the root-layout attribute "isScrollContainer" to "false" doesn't work because i'm using linear layouts and it respects the weight distribution none the less. – Tejas Jan 28 '17 at 06:20
  • Try this Code may be it will help you http://stackoverflow.com/a/41038631/4427519 – Dhara Patel Jan 28 '17 at 06:23
  • try with `android:windowSoftInputMode="adjustResize|stateHidden"` – Kishore Jethava Jan 28 '17 at 06:44
  • @kishorejethava my current set-up is android:windowSoftInputMode="adjustResize|stateHidden – Tejas Jan 28 '17 at 07:23
  • whats problem? it's working perfect in mine – Kishore Jethava Jan 28 '17 at 07:29
  • Its working fine for me too. The thing is if you see the images above LinearLayout 1 that covers 60 % of the screen shrinks to take up 60% of whatever the amount of space is left after the keyboard show up. I want this layout to get pushed above the visible screen just like how it would if i use "adjustPan" – Tejas Jan 28 '17 at 07:36

1 Answers1

0

So here is what I think you should do, use

windowSoftInputMode="adjustResize" - The activity's main window is always resized to make room for the soft keyboard on screen. Also adjustResize keeps the ToolBar on top.

Try adding both your LinearLayouts inside a NestedScrollView. The reason I say this is because your NestedScrollView contents can scroll up.

I think your Layout will look like this- .

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

<LinearLayout
    android:id="@+id/view_group_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimaryDark"
        android:elevation="4dip" >

        <!-- Toolbar stuff -->

    </android.support.v7.widget.Toolbar>

</LinearLayout>


<NestedScrollView 
    android:layout_above="@+id/bottom_bar"
    android:layout_below="@+id/view_group_toolbar">
  <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

        <include
            layout="@layout/layout_that_covers_60%_of_the_screen (This is not my actual layout name :/ using it for understandability)"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/view_group_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4"
        android:gravity="center_vertical">

        <include
            layout="@layout/layout_that_covers_40%_of_the_screen"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

  </LinearLayout>
</NestedScrollView>
<RelativeLayout
    android:id="@+id/bottom_bar"
    android:layout_width="match_parent"
    android:layout_height="60dip"
    android:layout_alignParentBottom="true"
    android:gravity="bottom"
    android:padding="8dip" > 
        <!-- This is where my edit text resides -->

</RelativeLayout> 

Let me know if this works for you.

EDIT 1: If you have a RecyclerView inside your layouts, you may need to set this attribute for smooth scroll -

recyclerView.setNestedScrollingEnabled(false);
karthik prasad
  • 738
  • 7
  • 15