How to make the layout scrollable when the keyboard is active?
Use
Scroll View
as YourRoot Layout
.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
Also add this to your
Manifest
.
<activity android:name="YourActivity"
android:windowSoftInputMode="adjustResize" />
Can not get ScrollView to scroll when soft keyboard is shown
Add android:windowSoftInputMode="adjustResize"
to the <activity>
tag in your AndroidManifest.xml. This will cause the screen to be resized to the space left over after the software keyboard is shown. As a result, you will be able to scroll, since the screen will not be covered by the keyboard in any way.
EDIT:
I have written a minimal example and tested it. Unless there is a huge misunderstanding, try this code and then figure out why yours doesn't work:
xml layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_height="2000dp"
android:layout_width="wrap_content"
android:gravity="top"
android:text="Scroll Down!"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="Enter Text"
/>
</LinearLayout>
</ScrollView>
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="15"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MyActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
ScrollView doesn't work when keyboard is up
Finally, I found the solution.
I just changed the Scrollview's
parent to RelativeLayout
(instead of LinearLayout
).
I don't know why, but it fixed the issue. Maybe in layouts that its main Layout is RelativeLayout, Scrollview's parent should be a RelativeLayout! (But I'm not sure)
Here is fixed code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:background="#03A9F4"
android:gravity="center"
>
<RelativeLayout
android:id="@+id/main"
android:layout_width="310dip"
android:layout_height="485dip"
android:background="#03A9F4"
android:gravity="center">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="435dip"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="false"
android:background="@drawable/border_signup_signin_auth">
<!--It changed to RelativeLayout and fix the problem-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dip"
android:orientation="vertical"
tools:ignore="UselessLeaf">
</LinearLayout>
<ScrollView
android:id="@+id/ScrollMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dip"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingLeft="10dip"
android:paddingRight="10dip">
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:paddingEnd="5dip"
tools:ignore="RtlSymmetry">
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dip"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingLeft="10dip"
android:paddingRight="10dip">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:paddingEnd="5dip"
tools:ignore="RtlSymmetry">
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dip"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingLeft="10dip"
android:paddingRight="10dip">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:paddingEnd="5dip"
tools:ignore="RtlSymmetry">
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dip"
android:orientation="vertical"
android:paddingEnd="10dip"
tools:ignore="RtlSymmetry">
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dip"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingLeft="5dip"
android:paddingRight="5dip">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<Button
android:id="@+id/btnSignUp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="test"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<Button
android:id="@+id/btnGuest"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="test"
android:textSize="16sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="false"
android:contentDescription="TODO"
app:srcCompat="@mipmap/signup"
tools:ignore="ContentDescription"/>
</RelativeLayout>
</LinearLayout>
And it wasn't necessary to add anything to Java's file or Manifest.
Related Topics
Upload an Image Using Google Volley
Lint Error "Do Not Treat Position as Fixed; Only Use Immediately..."
Opencv Image Comparison in Android
How to Detect Bluetooth State Change Using a Broadcast Receiver
Android Maps API V2 Draw Circle
Android Volley Sending Data Twice
Android - How to Set an Alarm to a Specific Date
Crop Video Before Encoding with Mediacodec for Grafika's "Continuous Capture" Activity
How to Change Actionmode Background Color in Android
How to Release Application Plugin Using Android Market
Android UI Design: Supporting Multiple Screens
Android Accessibility Service Detect Notification
Android Test Code Coverage with Jacoco Gradle Plugin
Android Notification with Buttons on It
Kitkat Kills: Not Allowed to Load Local Resource: File:///Android_Asset/Webkit/Android-Weberror.Png
Google Geocoder Service Is Unavaliable (Coordinates to Address)