Reputation: 273
I am very new to using ConstraintLayout. In trying to learn to use this, I decided to make a simple chat app for myself.
I have a RecyclerView to show chat list and a ConstraintLayout under it for typing in my message (my code is at the bottom). I would very much want to use "fill-parent" attribute but I found that it's deprecated.
So I have set my RecyclerView to be constrained at the bottom by the ConstraintLayout below it. From this I am expecting the RecyclerView to "shrink" when the keyboard comes up to type my message in. However, it is not doing so, but rather stays at its full height.
Are there ways to resolve this?
Here's my code :
<android.support.constraint.ConstraintLayout
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"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tools:context=".StreamPlayer.StreamPlayerActivity">
<android.support.v7.widget.RecyclerView
android:id="@id/ChatRecyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="@id/ChatTypingLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/chat_layout" /
<android.support.constraint.ConstraintLayout
android:id="@id/ChatTypingLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<EditText
android:id="@id/ChatNameEditText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="@string/ChatNameEditText"
android:inputType="text"
android:maxLines="1"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/ChatMessageEditText"
app:layout_constraintStart_toStartOf="parent"
android:textSize="10dp"/>
<EditText
android:id="@id/ChatMessageEditText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="@string/ChatMessageEditText"
android:inputType="textLongMessage"
android:maxLines="3"
app:layout_constraintHorizontal_weight="4"
app:layout_constraintLeft_toRightOf="@id/ChatNameEditText"
app:layout_constraintRight_toLeftOf="@id/ChatSendButton"
android:textSize="10dp"/>
<Button
android:id="@id/ChatSendButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/ChatSendButton"
app:layout_constraintHorizontal_weight="2"
app:layout_constraintLeft_toRightOf="@id/ChatMessageEditText"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
This is when the keyboard has not come up
This happens when the keyboard comes up
Thanks in advance
Upvotes: 1
Views: 781
Reputation: 514
Check out this article on the Android developers' site which describes how the framework handles the soft keyboard appearing.
The android:windowSoftInputMode
attribute can be used to specify what happens on a per-activity basis: whether the layout is resized or whether it scrolls etc.
Answer from Christopher Orr
You can also try this in your onCreate()
method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Upvotes: 1
Reputation: 61
I think you should consider taking the second ConstraintLayout and making everything in one, that is the main purpose of the ConstraintLayout, avoiding nested layouts. And, how are you initializing your recycler view in code? are you setting a fixed height?
Upvotes: 0