How to push Activity content up when Keyboard activated - android

In an Activity of my Application, the user has to submit many Strings trough an EditText and a Button. As the range of the submits can go from a minimum of 9 to a maximum of 24, I want this process to be as easy and fast as possible.
I was thinking about making the Keyboard always visible while the whole Activity content gets pushed up.
I have tried to use the following rule in the Manifest to make it push the Activity android:windowSoftInputMode="adjustResize" but it looks like it only pushes up the content with a marginBottom.
Any ideas bout how to achieve this?
EDIT:
The following is the XML code of the Layout of my Activity:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.FET.leonardo.scurcola.NameSelection"
android:background="#e0ab18">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/whoMaster"
android:textColor="#color/white"
android:textSize="50sp"
android:layout_marginTop="50dp"
android:textAlignment="center"
android:id="#+id/whoMaster"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="#string/master"
android:ems="10"
android:textColorHint="#color/white"
android:textColor="#color/white"
android:textColorHighlight="#color/white"
android:id="#+id/names"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/next"
android:layout_marginBottom="50dp"
android:onClick="addPlayer"
android:text="#string/next"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/names"
android:textColor="#e0ab18" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"
android:id="#+id/back"
android:enabled="false"
android:onClick="removePlayer"
android:textColor="#e0ab18"
android:layout_marginBottom="50dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/names" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/finish"
android:visibility="gone"
android:text="#string/finish"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/names"
android:layout_marginBottom="50dp"
android:onClick="toNextActivity"
android:textColor="#e0ab18"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/zero"
android:textSize="50sp"
android:textColor="#color/white"
android:id="#+id/playersLeft"
android:layout_below="#+id/names"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
</RelativeLayout>
</ScrollView>

Apart from setting that option android:windowSoftInputMode="adjustResize", you can try using a ScrollView
Having so many fields can have some downside to your application speed - since every single element has to be drawn and that can be expensive. This will in turn affect your UI thread and could eventually cause app crashing.
Using a ScrollView, you can be able to scroll up and down through your EditText elements.
To speed up your application loading, for example if you have a lot more EditTexts, you can load half the elements/widgets when activity is loaded and once the user has started typing into the first field, load the rest.
This is an approach I have used several times and should work just fine!
Good luck and please let me know if this helps!
UPDATE
To have a scrollable view, make your root layout a ScrollView - remember it can only have 1 child.
<ScrollView
....
....
..... >
<RelativeLayout
....
....
..... >
<EditText />
...
</RelativeLayout>
</ScrollView>
So, basically you have a ScrollView as the root! That will enable you to scroll up the view and have the keyboard below or at the bottom!

Related

Android Tv button is not selected

I encountered a problem with the display layout.
Relativelayout #+id/media is not visible when you put visible. He remains under Relativelayout #+id/media2,is selectable from dpad but remains under the other.
if the parts and put media2 first and second media. When media is visible, but can not be selectable dpad.
there is a certain order to make the media though is written first be above the media2?
Thank you
layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/app_video_box"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/media"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_vertical|center_horizontal|center"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:animateLayoutChanges="true"
android:background="#e72a2a"
android:id="#+id/relativeLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:id="#+id/button2"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/button"
android:layout_toEndOf="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:id="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/button3"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/button2"
android:layout_toEndOf="#+id/button2" />
</RelativeLayout>
<SeekBar
android:id="#+id/app_video_seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:layout_above="#+id/relativeLayout"
android:layout_alignLeft="#+id/relativeLayout"
android:layout_alignStart="#+id/relativeLayout"
android:layout_alignRight="#+id/relativeLayout"
android:layout_alignEnd="#+id/relativeLayout" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/media2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<tcking.github.com.giraffeplayer.IjkVideoView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</RelativeLayout>
It seems like you're trying to control the focus on different items on screen. You can use XML tags specifically for this:
android:nextFocusForward="#+id/media2"
android:nextFocusDown="#+id/media2"
You can look at the docs for keyboard navigation to learn more.
In Android TV, only ui elements gets selected only if they are focusable.
Achieve this either through xml attributes or by code.
view.setFocusable(true)
or
android:focusable="true".
And set rules for each ui elements to whom the focus to be transferred.
android:nextFocus{direction}="view_id".
where direction could be down, top, right or left.
focusable items

Android button overlapping text layout when typing

I am programming an Android app which has an initial screen that works fine. The problem is that, when typing, a button overlaps the text, as you can see here:
Here is the code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.app.InitialActivity"
tools:showIn="#layout/activity_initial">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome to app"
android:layout_marginTop="50dp"
android:id="#+id/textViewTitle"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textViewTitle"
android:layout_marginLeft="15dp"
android:layout_marginTop="50dp"
android:layout_marginRight="15dp"
android:inputType="textEmailAddress"
android:textSize="17sp"
android:hint="Enter your email"
android:ems="10" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editTextEmail"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
android:inputType="textPassword"
android:textSize="17sp"
android:hint="Enter your password"
android:ems="10" />
<Button
android:id="#+id/loginButton"
android:text="Login"
android:layout_centerVertical="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editTextPassword"
android:layout_marginLeft="15dp"
android:layout_marginTop="25dp"
android:layout_marginRight="15dp" />
<Button
android:id="#+id/registerButton"
android:text="Register"
android:layout_centerVertical="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/loginButton"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:layout_marginRight="15dp" />
<Button
android:id="#+id/forgotPasswordButton"
android:text="Forgot Password?"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp" />
</RelativeLayout>
</ScrollView>
Any help will be much appreciated, thanks in advance.
When I was starting with Android development I was used to work with RelativeLayout too (I'm not an expert, I'm just telling my experience). At first, it looks like the most appropriate layout, but one thing that you should keep in mind is: let the system take care of the things to you, in other words, RelativeLayout is totally dependent from what you're saying, so with you don't think about new screen resolution, or an old one, the whole layout could become a mess.
The goal is, tell the Android what you want without using specific parameters (or at least try to avoid those). I agree with #klaymen: for different orientations you should use more than just one layout.
Just for an example, see the code below (it's a remake of your 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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.app.InitialActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome to app"
android:id="#+id/textViewTitle" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/editTextEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:textSize="17sp"
android:hint="Enter your email"
android:ems="10" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textSize="17sp"
android:hint="Enter your password"
android:ems="10" />
<Button
android:id="#+id/loginButton"
android:text="Login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editTextPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:weightSum="2"
android:orientation="horizontal">
<Button
android:id="#+id/registerButton"
android:text="Register"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/forgotPasswordButton"
android:text="Forgot Password?"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
There's a little things here that are importants and could help you a lot in the next tries (look for these properties in the code above):
android:layout_gravity;
Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.
android:gravity;
Specifies how an object should position its content, on both the X and Y axes, within its own bounds.
android:weightSum;
Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.
Must be a floating point value, such as "1.2".
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol weightSum.
android:layout_weight;
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.
I hope that helps you. One more thing use your IDE in favor, generate some examples and look how they work (they used to be dynamic), I'm pretty sure that you will learn a lot with this exercise.
Good Luck!
One way to overcome this problem would be to use android:windowSoftInputMode="adjustNothing" inside your activity tag.
<activity name="YourActivity"
android:windowSoftInputMode="adjustNothing">
...
</activity>
However, keep in mind that in this case the register button will be covered by the keyboard.
You have set each view relative to another in the page.
You'd better place all of your elements in the page relative to one element or relative to main layout.
This problem is because of using "Relative Layout".
Another option is using an simpler layout like linear layout inside the relative layout to simplify things.

views get hide on orientation change from portrait to landscape in android mobile application

there is an activity in my application. In this i am taking few values from user using some Editboxes. the problem is that if the phone's orientation is portrait then i can see all the EditBoxes and buttons but when the orientation changes to landscape the buttons get hide and i can see only the first 3 Editboxes and nothing else. All i want is that if such a case appears and the size of the layout gets more than a height of phone, then a scroll should appear so that i can scroll down to see the below fields and buttons. Is there a better way to do it ???? (using a different layout for landscape mode will cause recreating the activity which i do not want)
Below is the code for my activity
<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="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.name.package.service">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/title_text_size"
android:textStyle="bold"
android:gravity="center_horizontal"
android:id="#+id/tv_lable"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_serivce_description"
android:gravity="left"
android:text="#string/plumber_service_description"
android:textSize="#dimen/description_text_size"
android:layout_marginTop="#dimen/large_margin"
android:layout_below="#id/tv_book_service_title_lable"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name :"
android:id="#+id/tv_customer_name_label"
android:layout_below="#id/tv_serivce_description"
android:layout_marginTop="#dimen/huge_spacing"
android:textSize="#dimen/label_text_size"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_customer_name"
android:layout_alignBottom="#id/tv_customer_name_label"
android:layout_toRightOf="#id/tv_customer_name_label"
android:layout_marginLeft="#dimen/normal_margin"
android:hint="fiil your name"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email :"
android:id="#+id/tv_customer_email_label"
android:layout_below="#id/tv_customer_name_label"
android:layout_marginTop="#dimen/large_spacing"
android:textSize="#dimen/label_text_size"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_customer_email"
android:layout_alignBottom="#id/tv_customer_email_label"
android:layout_toRightOf="#id/tv_customer_email_label"
android:layout_marginLeft="#dimen/normal_margin"
android:hint="fiil your email"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact :"
android:id="#+id/tv_customer_contact_label"
android:layout_below="#id/tv_customer_email_label"
android:layout_marginTop="#dimen/large_spacing"
android:textSize="#dimen/label_text_size"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_customer_contact"
android:layout_alignBottom="#id/tv_customer_contact_label"
android:layout_toRightOf="#id/tv_customer_contact_label"
android:layout_marginLeft="#dimen/normal_margin"
android:hint="fiil your email"
android:gravity="center_horizontal"
android:marqueeRepeatLimit="marquee_forever"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_service_description_label"
android:text="Description"
android:textSize="#dimen/label_text_size"
android:layout_below="#id/tv_customer_contact_label"
android:layout_marginTop="#dimen/large_spacing"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_service_description"
android:layout_below="#id/tv_service_description_label"
android:layout_marginTop="#dimen/large_margin"
android:hint="What service you need ?"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book Service"
android:gravity="center_horizontal"
android:layout_below="#id/et_service_description"
android:layout_marginTop="#dimen/large_margin"
android:layout_centerHorizontal="true"
/>
i have also used below settings for the activity in manifest file
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTop"
Thanks in advance for sharing the knowledge ....:D
Wrap your layout which is RelativeLayout within a Scrollview. If the layout does not fit within the window then scrolls are enabled for you to scroll and view all your views else they will not be visible on screen.
Usage
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollViewid"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
-------add your RelativeLayout ------
</ScrollView>
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.
Please use LinearLayout instead of RelativeLayout it will solve your problem

Software keyboard move editTexts for android

I'm trying to get the editTexts, and sign in button to move up when the software keyboard is out however I want the background to not be compressed(I'm going to add an image soon). I have the TextView(Login), two EditTexts(email and password) and signin button in a ScrollView because I thought that might help however I have not be able to figure anything out.
http://i.imgur.com/vlYifc6.png
http://i.imgur.com/vlYifc6.png
This is the xml
<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="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:id="#+id/textLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login"
android:id="#+id/loginView"
android:textSize="22dp"
android:layout_above="#+id/textLayout"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/emailTextfield"
android:inputType="textEmailAddress"
android:background="#android:drawable/edit_text"
android:textColor="#android:color/primary_text_light"
android:text="andresc1305#yahoo.com"
android:hint="Email" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"
android:text="Andres123"
android:background="#android:drawable/edit_text"
android:textColor="#android:color/primary_text_light"
android:ems="10"
android:id="#+id/passwordTextfield" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIGN IN"
android:background="#android:color/transparent"
android:textSize="24dp"
android:id="#+id/signinButton"
android:layout_below="#+id/textLayout"
android:layout_centerHorizontal="true"
android:onClick="onSigninClick"/>
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot your password?"
android:background="#android:color/transparent"
android:textSize="14dp"
android:id="#+id/forgotButton"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="onPasswordRecoverClick"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:background="#android:color/transparent"
android:textSize="14dp"
android:id="#+id/registerButton"
android:layout_alignTop="#+id/forgotButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="onRegisterClick"/>
</RelativeLayout>
Look at this answer. In short, your problem can most likely be solved by setting the following in your AndroidManifest.xml inside the relevant activity or application element:
android:windowSoftInputMode="adjustResize"
#PPartisan
This is without:
android:windowSoftInputMode="adjustResize"
http://i.imgur.com/tbNioU2.png
This is with:
http://i.imgur.com/7ZePHjS.png
Beside the compression you can see my "Forgot your password" and "Register" buttons but I have those outside my ScrollView in the XML. Is there a way to scroll the LinearLayout (which contains the Login(TextView, email(EditText), password(EditText), and Signin(button) up when the software keyboard comes up?
The answer by zmilojko seems like what I want to do but he only says to add the ScrollView and not what to do after that has been added. Is there something I can place in the to make it move up when the software keyboard comes up?
see this thread, i think it can help you
layout of the screen moves up when keyboard is displayed
or just try to put this in your xml:
android:windowSoftInputMode="adjustPan"
or this
android:windowSoftInputMode="adjustNothing"
Seems like it works different in each case.

Android: Make layout scrollable when keyboard comes up

This is a follow up to this question.
Have spent days on this issue, and can't seem to get what I want. What I need very simply is this entire view to be scrollable when the keyboard pops up after touching an edittext field:
Note that this view is not scrollable, it doesn't need to be.
So when the user hits the edittext field (say the first one), it looks like this:
And if he/she chooses, the view can be scrolled to end no further that the way it looks here:
I've tried every combination of scrollview I could think of, but all it does is stretch my background image. I'm sure there is a simple solution to this, but I just can't find it. I would really be grateful to anyone who can solve this problem. Here is the XML for the layout by the way:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:orientation="vertical"
android:paddingLeft="60dp"
android:paddingTop="53dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText1"
android:layout_marginTop="3dp"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText2"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText2"
android:layout_marginTop="3dp"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText3"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/textView3"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText3"
android:layout_marginTop="3dp"
android:text="text4" />
<ImageView
android:id="#+id/gearImage3"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignLeft="#+id/button1"
android:layout_below="#id/button1"
android:layout_marginTop="70dp"
android:clickable="true"
android:contentDescription="#string/gearDescription_string"
android:src="#drawable/gear" />
</RelativeLayout>
Kindly note the latter two images are not from the real app (photoshopped to show what I need) but the first one is from my app. Thanks.
A ScrollView only scrolls to as far as there is data. So simply adding a ScrollView should just fix your problem. Add this to the start of your xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
and then obviously add this at the bottom, after everything else:
</ScrollView>
I use this in my app and when the keyboard shows, I can still scroll to the bottom of the page. If your fields as shown in screenshot 1, are not longer than one normal phone page, it won't scroll anyway. It will only scroll when you have the keyboard up as it can't then see the whole screen.
Hope this helps!

Categories

Resources