I have an activity with a form. I put all views in a ScrollView because when the keyboard opens, I would scroll through the fields.
When the keyboard opens, the first field goes over the top of the ScrollView and becomes unreachable.
This is the layout:
<ScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<EditText
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Username"
android:inputType="text|textEmailAddress"
android:singleLine="true" />
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true" />
<EditText
android:id="#+id/password1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="#string/repeat_password"
android:inputType="textPassword"
android:singleLine="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/gender" />
<RadioGroup
android:id="#+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp">
<RadioButton
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="M" />
<RadioButton
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="F" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/age" />
<EditText
android:id="#+id/age"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:paddingLeft="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/education" />
<Spinner
android:id="#+id/education"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:onClick="salva"
android:text="#string/save" />
</LinearLayout>
</ScrollView>
This is the activity definition in the manifest:
<activity
android:name=".activities.SignUpActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_sign_up">
</activity>
This is a screenshot. The username field is unreachable! (look at the scrollbar on the right)
Use following in your App Manifest
android:windowSoftInputMode="stateHidden|adjustPan"
For more details you can visit here
http://developer.android.com/guide/topics/manifest/activity-element.html
In your activity manifest entry add this:
android:windowSoftInputMode="stateVisible|adjustPan".
I've found the solution. The problem was this line:
android:layout_gravity="center"
I just removed it from the layout file. The manifest was correct.
Related
my keyboard keeps blocking my view. Is there anyway to fix this?
When I click the Description 2 to insert something, But the keyboard so annoying... I can't see what I'm typing... Actually This isn't one page. Others page also like this. I can't see what I'm typing, Only when I close the keyboard then okay can see the things.
Here is the code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="300dp"></ListView>
</LinearLayout>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="DATE:" />
<TextView
android:id="#+id/Select_Date"
android:layout_width="60dp"
android:layout_height="38dp"
android:text="SELECT DATE"
android:textSize="19dp"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="TXN NO:" />
<TextView
android:id="#+id/D_Txn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="NAME:" />
<EditText
android:id="#+id/D_Name"
android:layout_width="273dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="AMOUNT:" />
<EditText
android:id="#+id/D_Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="110dp"
android:layout_height="wrap_content"
android:text="DESCRIPTION1:" />
<Spinner
android:id="#+id/D_Description"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="#android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="DESCRIPTION2:" />
<EditText
android:id="#+id/Ds_Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="horizontal">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<Button
android:textColor="#color/my_color_state"
android:id="#+id/Db_New"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="NEW" />
<Button
android:textColor="#color/my_color_state"
android:id="#+id/Db_Save"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:enabled="false"
android:text= "SAVE" />
</TableRow>
<TableRow>
<Button
android:textColor="#color/my_color_state"
android:id="#+id/Db_Print"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="PRINT" />
<Button
android:textColor="#color/my_color_state"
android:id="#+id/Db_Back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="BACK" />
</TableRow>
</TableLayout>
</LinearLayout>
In your manifest, add this line to your activity:
android:windowSoftInputMode="adjustResize"
It adjusts your activity when the available layout size changes.
EDIT:
You'll also have to add a ScrollView over the main container in your case.
Go to your Manifest and add this line for the selected activity
android:windowSoftInputMode="adjustPan"
Example:
<activity
android:name=".Activity.MainActivity"
android:label="#string/title_activity_main"
android:windowSoftInputMode="adjustPan">
scroll view is working without keyboard But it is not working when keyboard comes i have also tried "android:windowSoftInputMode="adjustResize|stateHidden" no use i dont understand please explain what is happening `
<?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="fill_parent"
android:fillViewport="true"
android:background="#drawable/background"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_weight=".85"
android:background="#drawable/logo" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight=".15"
android:gravity="center"
android:text="Fill in the below to get Started"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<EditText
android:id="#+id/sig_user"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:layout_margin="3dp"
android:layout_weight=".5"
android:background="#drawable/rounder_edittext"
android:hint=" User name"
android:inputType="textEmailAddress"
android:drawableStart="#drawable/user"
android:drawablePadding="10dp"
android:padding="10dp"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textColorHint="#android:color/white"
android:textSize="18sp"
android:drawableLeft="#drawable/user" />
<EditText
android:id="#+id/sig_password"
android:layout_width="match_parent"
android:layout_height="55dp"
android:drawableStart="#drawable/lock"
android:drawablePadding="10dp"
android:padding="15dp"
android:layout_gravity="center_horizontal"
android:layout_margin="3dp"
android:layout_weight=".5"
android:background="#drawable/rounder_edittext"
android:hint=" Password"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textColorHint="#android:color/white"
android:textSize="18sp"
android:drawableLeft="#drawable/user" />
<EditText
android:id="#+id/sig_email"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:layout_margin="3dp"
android:layout_weight=".5"
android:background="#drawable/rounder_edittext"
android:hint=" E-mail"
android:inputType="textEmailAddress"
android:drawableStart="#drawable/mail"
android:drawablePadding="10dp"
android:padding="10dp"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textColorHint="#android:color/white"
android:textSize="18sp"
android:drawableLeft="#drawable/user" />
<EditText
android:id="#+id/sig_phone"
android:layout_width="match_parent"
android:layout_height="55dp"
android:drawableStart="#drawable/phone"
android:drawablePadding="10dp"
android:padding="15dp"
android:layout_gravity="center_horizontal"
android:layout_margin="3dp"
android:layout_weight=".5"
android:background="#drawable/rounder_edittext"
android:hint=" Phone"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textColorHint="#android:color/white"
android:textSize="18sp"
android:drawableLeft="#drawable/user" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/signup"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/white_button"
android:text="creat account"
android:textColor="#f29925" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
`
Add android:windowSoftInputMode="stateHidden|adjustResize" to your tag in AndroidManifest.xml file. This will cause the screen to be resized to the left over space after the soft keyboard is shown. So, you will be able to scroll easily.
In Manifest.xml file like this.
<activity android:name="MyActivity"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize"
>
When I'm trying to add ScrollView its giving me error that Scroll view can contain only a single child. So how to add a ScrollView ?
And also when I open my app in various phones all the phones gives different layouts. How do manage the look and feel of the app same for all mobile devices ?
Register.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#0066CC"
android:orientation="vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/upImage"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView1"
android:layout_width="465dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.02"
android:layout_marginBottom="100dp"
android:textSize="15sp"
android:textStyle="bold"
android:text="Tap to upload Profile Picture" />
<EditText
android:id="#+id/imName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:hint="Enter name of the Image"
android:ems="10" >
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age" />
<EditText
android:id="#+id/etAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textPassword" />
<Button
android:id="#+id/bRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
Yes ScrollView allow only single child
So put you parent LinearLayout inside ScrollView like below
<ScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0066CC"
android:orientation="vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/upImage"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView1"
android:layout_width="465dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.02"
android:layout_marginBottom="100dp"
android:textSize="15sp"
android:textStyle="bold"
android:text="Tap to upload Profile Picture" />
<EditText
android:id="#+id/imName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:hint="Enter name of the Image"
android:ems="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age" />
<EditText
android:id="#+id/etAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textPassword" />
<Button
android:id="#+id/bRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
</ScrollView>
Android only supports a single child inside a ScrollView. The simplest way is to enclose everything inside a LinearLayout and make it a child of a ScrollView.
If you however want to maintain the same look and feel throughout the application, try using a RelativeLayout instead of the LinearLayout as the child of the ScrollView.
I would like to move a single element (relative layout) of my layout above the software keyboard when an editText is focused.
I've tried to set android:windowSoftInputMode with adjustResize in my manifest but as I seen in many other stackoverflow questions it works only with the entire Activity.
So, is it possible to move a single element above the keyboard?
I hope the following sample helps.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:id="#+id/scrollView1" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_weight="1">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<EditText android:id="#+id/editText1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText1" />
<EditText android:id="#+id/editText2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText2" />
<EditText android:id="#+id/editText3" android:layout_height="wrap_content"
<EditText android:id="#+id/editText4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText4" />
<EditText android:id="#+id/editText5" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText5" />
<EditText android:id="#+id/editText6" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText6" />
<EditText android:id="#+id/editText7" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText7" />
<EditText android:id="#+id/editText8" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText8" />
<EditText android:id="#+id/editText9" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="EditText9" />
</LinearLayout>
</ScrollView>
<LinearLayout style="#android:style/ButtonBar" android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<Button android:id="#+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Button"></Button>
</LinearLayout>
</LinearLayout>
http://www.androidpub.com/?document_srl=1703090&mid=android_dev_qna&comment_srl=1704523&rnd=1704523#comment_1704523
Name, password1 field not showing up in scrollview
everything else working properly
here is my xml for it..
Made a linear layout after scrollview as it supports only one child.
Any idea what is the problem ?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name" />
<EditText
android:id="#+id/password1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword" />
<EditText
android:id="#+id/password2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/retype"
android:inputType="textPassword" />
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/email"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender" />
<RadioGroup
android:id="#+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<ImageView
android:id="#+id/capcha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/typecaptcha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Type" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
</ScrollView>
</LinearLayout>
For me the Password field works, seems fine (I copied you XML to test it). If you use eclipse try Project>Clean. I had similar Problems.
Happy Coding
EDIT(Result):