1

I inflate a pop-up layout, where I implement some kind of chat. At the bottom (align parent bottom) I have EditText, where I can type message. And I have a ScrollView with LinearLayout, that uses left space of a layout. Messages appear in ScrollView. The problem is how to move elements when keyboard is shown. For example, I tap on EditText and soft keyboard appears above EditText, so I don't see what I'm typing. How to move it?

I tried to use windowSoftInputMode in manifest with adjustResize or adjustPan but it didn't help.

XML:

<?xml version="1.0" encoding="utf-8"?>
<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="320dp"
    android:layout_height="500dp"
    tools:context="shkatovl.osanka.MainActivity"
    android:background="@drawable/border_popup"
    android:focusable="true">

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

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



            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="350dp"
                android:layout_marginTop="100dp"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="58dp">

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

                </LinearLayout>
            </ScrollView>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="58dp"
                android:background="@drawable/rect8"
                android:layout_alignParentBottom="true">

                <EditText
                    android:id="@+id/etDialog"
                    android:layout_width="244dp"
                    android:layout_height="38dp"
                    android:textSize="16sp"
                    android:textColor="@color/font"
                    android:hint="Сообщение"
                    android:paddingStart="15dp"
                    android:textColorHint="@color/font40"
                    android:background="@drawable/rect9"
                    android:theme="@style/EditText"
                    android:text=""/>

            </RelativeLayout>

    </ScrollView>

</RelativeLayout>
Tryam
  • 375
  • 2
  • 13
  • did you try to setSoftInputMode inside your onCreate()? also it would be good to include parts of your code – Noel Dec 09 '17 at 13:03
  • You should probably try to make scrollview.post(new Runnable() { @Override public void run() { scrollview.scrollTo(0, editText.getBottom()); } }); – Yurii Kot Dec 09 '17 at 13:08
  • @YuriyKot could you explain, please? What will it do? – Tryam Dec 09 '17 at 13:14
  • @Noel, Yes, just tested. It didn't help – Tryam Dec 09 '17 at 13:29
  • try again but put your RelativeLayout inside your tags.. i really think that's the problem here. – Noel Dec 09 '17 at 13:36
  • @Noel, I tried to wrap everything I have, except main RelativeLayout, in a ScrollView with one RelativeLayout (because it should have one child). But it didn't help – Tryam Dec 09 '17 at 13:43
  • This is all your XML? if so i think you need a layout to be set as a parent to all these other layouts.. of this does not work I'm out of ideas.. – Noel Dec 09 '17 at 13:50
  • @Noel, I just updated the post with more simple code – Tryam Dec 09 '17 at 13:55
  • did you check this :- https://stackoverflow.com/questions/1964789/move-layouts-up-when-soft-keyboard-is-shown , https://stackoverflow.com/questions/9111813/how-to-move-the-layout-up-when-the-soft-keyboard-is-shown-android – InsaneCat Dec 09 '17 at 13:59
  • @InsaneCat, Yes, I tried both `adjustPan` and `adjustResize`. Also programmatically – Tryam Dec 09 '17 at 14:04
  • Set up on keyboard opened\closed listener https://stackoverflow.com/questions/25216749/softkeyboard-open-and-close-listener-in-an-activity-in-android and make scrollview.scrollTo(0, editText.getBottom()); – Yurii Kot Dec 09 '17 at 16:18

0 Answers0