Jochem Groot Roessink Jochem Groot Roessink - 1 month ago 11
Android Question

Only change position of editText when typing android

When I am in my app and I want to type the keyboard pops up but also all the elements in the app go up. I would like to know how I can only make the editText and its button go up and let the other elements keep their position. This is my code (just began coding):

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.jochem.chatbot.MainActivity"
android:background="#ffffff">

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="@mipmap/ic_launcher"
android:background="#00ffffff"
android:onClick="changeText" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignBottom="@+id/imageButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/imageButton"
android:layout_toStartOf="@+id/imageButton"
android:textSize="20dp"
android:textColor="#000000"
android:hint="Yeah, typ something"
android:textColorHint="#505050"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Typ something"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton"
android:textColor="#000000"
android:textSize="25dp" />

</RelativeLayout>

Answer

For me works adding android:windowSoftInputMode="adjustResize" in manifest for <activity> tag.

Here you have docs: https://developer.android.com/guide/topics/manifest/activity-element.html

Comments