Issue in Android Layout - SoftKeyboard - Layout alignment - android

Hello Am working on some layout design in Android.
Layout contains an EditText inside Relativelayout and alignparentBottom='true' is given to Relativelayout.
When Soft-keyboard opens, My Views remains same - this is okay.
But, The Relativelayout which is inside bottom in screen : which contains EditText is not coming upper side of my SoftKeyboard.
So far, I have done as below to solve but getting an issue explained above: (with adjustPan, my bottom layout is coming upperside of softkeyboard but, it also scrolls the whole screen upper.)
In Manifeast :
android:windowSoftInputMode="adjustResize"
<activity
android:windowSoftInputMode="adjustResize"
android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="Camera Activity"
android:screenOrientation="portrait" />
What might be the solution?
thanks.

Try using ScrollView as parent view:
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
and remember that scrollview accepts only one direct child, so wrap your whole layout inside it.
also use linearLayout insted of relativeLayout, something like this:
<ScrollView>
<LinearLayout orientation="vertical">
<LinearLayout orientation="vertical">
<EditTexts />
</LinearLayout>
<Button />
</LinearLayout>

Related

Stop softkey from pushing toolbar above screen

My layout looks something like this
<LinearLayout>
<Toolbar/>
<Scrollview>
<More views including a edittext in the bottom/>
</Scrollview>
</LinearLayout>
The problem is that whenever I select the editext to type something the softkey pushes the edittext up, which is how it's supposed to work but the entire layout is pushed up along with it.. I want to keep the toolbar on the screen, just like how it is in WhatsApp where the toolbar remains on the screen when the edittext is pushed up and down by the softkey.
just set
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false">
and also add this in your linearlayout
android:windowSoftInputMode="adjustPan"

Android buttons at top and ScrollView at bottom of the screen

I have two buttons "Submit" and "Reset" on top of the ui and below this is my form. The problem is when i open my keyboard, the form scrolls up and goes below the top buttons layout. What should be the problem? I want to show buutons on top only.
try this
Replace to RelativeLayout to Linearlayout With orientation Vertical.
you can try to prevent the keyboard from scrolling up your form, so the keyboard will be above your layout by doing this :
add this to your manifest
<activity
android:name="yourActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustPan"/>
then put this inside your ScrollView
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false">
</ScrollView>
if any trouble leave a comment !
Good luck

Layout not pushed up when Soft keyboard appears

I have a fragment of this given layout hierarchy,
Inside the view pager I have a Edit text. When keyboard appears to type in the text to EditText the entire layout is not pushed up. Instead the contents inside ViewPager is pushed up. I want the entire content inside the Outer Linear Layout to be pushed up when keyboard appears.
How can I achieve this?
Thanks.
Put your Parent LinearLayout inside a scrollview. This fixed my issue.
put your base layout inside the ScrollView
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/llPlayersName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
// do here the layout work
</LinearLayout>
</ScrollView>
remember scrollView cannon be used as the base layout, so you have to put the scrollView inside the LinearLayout or RelativeLayout.
In your activity's manifest entry, add
<activity ...
android:windowSoftInputMode="adjustPan">

android: using adjustPan and without scrolling the title bar

I'm using android:windowSoftInputMode="adjustPan" in my manifest.xml.
It's doing me the job just fine but there is something retarded about it.
when i focus an EditText view that's, say in the bottom half of the screen, the title bar is also scrolled with the content of the activity.
image here
all i want is to freeze/float the title bar in place when scrolling the content. just like this:
image here
and no, I don't want to use adjustResize It overlaps views on top of each other
any help is greatly appreciated, been looking for the answer for a long time.
Found it!
Simply changing the root view in the layout xml file to a ScrollView does the job.
I don't even need to specify android:windowSoftInputMode
Of course I have to have everything else in a single layout as the child of the ScrollView
Edit
your .xml file should look like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
... >
<LinearLayout> // could be any other layout but linear works well here
//insert all other views of the activity here
</LinearLayout>
</ScrollView>
The answer suggested by Ace is essentially what is needed. My answer just aims to make things a little clearer.
There are two things you need to do. Firstly in the Manifest set the following on the activity. android:windowSoftInputMode="adjustResize"
Then, in the activity's layout you'll want to set a ScrollView beneath the Toolbar/Title Bar, as shown in the code below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
.../>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
From what I understand, here's how it works.
When you open the soft keyboard on your device, it will 'adjustResize' the layout of the activity. As the layout sits in a ScrollView, this is the part which is resized, and made smaller. Therefore the Toolbar/Titlebar will stay in place and the layout in the ScrollView will be scrollable when the keyboard is shown.

Why doesn't android:windowSoftInputMode="stateVisible|adjustResize" adjust the screen when soft keyboard is shown?

I can't seem to make the android:windowSoftInputMode="stateVisible|adjustResize" option work.
When the soft keyboard shows, the scroll view doesn't automatically scroll to the bottom part.
Edit: I tried using adjustPan instead (stateVisible|adjustPan) but what happens is the scroll view gets disabled.
Solution: Finally, I found a suggestion that works. I created an OnGlobalLayoutListener() and added it to my scroll view. I checked if the height of the root view of my activity(which is my scroll view) changed. If yes, I'm assuming that the soft keyboard is shown.
Click here for more info.
Here's my source code:
AndroidManifest.xml
<application
...
android:theme="#android:style/Theme.NoTitleBar" >
<activity
...
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
Login Screen with keyboard - scroll view does not scroll
Desired result
Solution: Finally, I found a suggestion that works. I created an OnGlobalLayoutListener() and added it to my scroll view. I checked if the height of the root view of my activity(which is my scroll view) changed. If yes, I'm assuming that the soft keyboard is shown.
Click here for more info.
try
android:windowSoftInputMode="adjustPan|stateVisible"
You could automatically scroll to the bottom of your activity by yourself, by overriding the onConfigurationChanged() callback in you Activity :
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
This means you also have to tell your activity you want the callback to be called when the activity changes its layout by using the configChanges attribute in the activity declaration in your AndroidManifest file :
<activity
android:configChanges="screenLayout|screenSize" <!-- Don't know which could actually do the trick -->
... >
</activity>
I hope this can help you.
In Manifest:
android:windowSoftInputMode="adjustPan|stateVisible"
In layout xml bottom of all child layout of scrollview set one textview, such as
<ScrollView
android:id="#+id/driverLoginScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
.
.
.
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:focusable="false"
android:textIsSelectable="false" />
</LinearLayout>
</ScrollView>
I found that if I had set layout parameters on my scroll view, then it would not work. As soon as a removed the layout parameters it worked as expected. I can't explain why, just letting others know what worked for me.

Categories

Resources