There is a LinearLayout
include a EditText
at the bottom of screen in my program when I tap EditText
to type some text, the keyboard is appeared and the EditText
height is shrinked, so I can't see what I wrote in EditText
.
I searched about this and found out that maybe it's about AndroidManifest.xml
file. So I add this line to the file:
android:windowSoftInputMode="adjustPan"
But this not work as I want after I added this code into manifest EditText
is placed behind the keyboard.
Finally I want to know is there any way to prevent resizing views while the keyboard is show?
My Activity XML 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:fitsSystemWindows="false">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/msgView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:background="@drawable/sssaaa">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:weightSum="10">
<EditText
android:id="@+id/txt_message"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="8.8"
android:background="@drawable/rounded_corner"
android:hint="@string/hint"
android:inputType="text"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000000" />
<Button
android:id="@+id/btn_send"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
android:background="@drawable/circular_button"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I found a workaround, since you are using the Constraint Layout
, I have separated the two Linear Layout
, the RecyclerView
and the send message field.
Since EditText
will always be on the screen and the RecyclerView
already contains a ScrollView they may be competing on the screen, RecyclerView
does not need to occupy the entire screen.
<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:fitsSystemWindows="false">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout">
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:weightSum="0"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/msgView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:weightSum="10">
<EditText
android:id="@+id/txt_message"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="8.8"
android:inputType="text"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000000" />
<Button
android:id="@+id/btn_send"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
To test I removed the lines that contained drawables, just put them back and run the code.
Notice that I change de height of the parent Linear Layout
of EditText
to 50dp