I have a layout that contains 5 EditText
and a Button
and a TextView
at bottom. Now when I press an EditText
then the keyboard will shown and all my View
is push up.
Now I don't want to push my TextView
and Button
to above keyboard, just only want to push up all EditText
inside ScrollView
to above keyboard.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 1"
/>
<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 2"
/>
<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 3"
/>
<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 4"
/>
<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 5"
android:inputType="textNoSuggestions"
/>
</LinearLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:text="I don't want to push this TextView and Button to above keyboard when keyboard is shown. Just obly want to push the ScrollView that contain all EditText"
/>
</LinearLayout>
I have an idea is. When I will listener when keyboard show and hide. When keyboard show I will set the bottom margin of ScrollView = keyboard height, when keyboard hide I will set this margin = 0.
Is there any way easier to handle my case? Any help or suggestion would be great appreciated.
UPDATE
If I use windowSoftInputMode=adjustPan
=> not all EditText
is push up to above keyboard
If I use windowSoftInputMode=adjustResize
=> Button
, TextView
and all EditText
is push up to above keyboard
Tested on all Nexus mobile and Tablet devices. It works fine. I am using your layout xml code and have added only id's to views.
I am using the below library in my production application and it is very promising. To achieve the same and add the below line in app gradle: 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.1' Here is the link for the same.
Refer to the below gist for the rest of the code:Manifest code, Activity code, Activity layout code.
Use a
Relavtive Layout
as parent with two Linear Layout as child and put the scrollview in first LinearLayout while the button with the textview in other one.Use this code. Have tested it, will work as you expect.
You must add
android:windowSoftInputMode="adjustPan"
in yourManifest
and It will work like a Pro:Please try to add this layout,
first change layout
then add class
And from activities onCreate
find id for rlBtm.
you may use below code ( But in this case your button and your textview was end of the screen. else your may manage it with Linear layout too. if you want button and textview must be show then pls ask.