First off all let me say that I've tried in the manifest android:windowSoftInputMode="adjustPan|stateHidden" and android:windowSoftInputMode="adjustResize|stateHidden" and the result is the same.
I have a layout with an Header and a Footer and in between I have an ScrollView. Inside this, I have a RelativeLayout and inside this layout, I have one EditText and a LinearLayout containing another EditText (this layout makes sense in my app).
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scroll"
android:layout_below="#+id/header"
android:fillViewport="true"
android:layout_above="#+id/footer">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="40dp">
<EditText
android:id="#+id/one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/edittextback"
android:layout_marginBottom="40dp" />
<LinearLayout
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/one"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
android:layout_marginBottom="40dp">
<EditText
android:id="#+id/two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittextback"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
When I enter the activity and start entering text in the first edittext, the keyboard pops up, the scroll goes up a little so the I can see the text that I'm inserting. The problem is that the edittext is not all visible (I mean the bottom boundary). The keyboard stays just bellow the inserted text and not bellow the bottom of the edittext.
Now, since I already have the keyboard open, I scroll a bit so that I can see the top of the second edittext. When I touch the second edittext, it gains focus, and now, it automatically scrolls a bit not like the first edittext, that is, just enough to see the inserted text, but to the bottom of the edittext making the edittext all visible. This is what I want.
How can I make the behavior to be show always all the edittext?
Related
There is a character counter under the pink line, which I would like to see while typing, but it's covered by the keyboard. Everything is inside a scroll view, and the text field scrolls up when focused, but I want to make it "overscroll" - how can we adjust the scroll offset, or whatever it's called?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/answer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/length_limit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewEnd"
android:maxLength="250"/>
</LinearLayout>
Look at this link Move layouts up when soft keyboard is shown?
or if you want to change margins check this
KeyBoard changing
And for implementing that :
onResume
I have a multi-line EditText, followed by a button below:
<RelativeLayout
android:id="#+id/main_content"
android:focusableInTouchMode="true"
style="#style/OuterLayout.InnerLayout"
android:layout_below="#+id/lineBelowTitleBar">
....couple of other textviews.........
<TextView
android:id="#+id/problem_details_title"
android:text="What can we help you with?"
android:layout_width="match_parent"
android:layout_height="#dimen/edittext_textSize_layout_height"
android:layout_below="#+id/line2"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/problem_details_title">
<EditText
android:id="#+id/problem_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:gravity="top"/>
</ScrollView>
</RelativeLayout>
<Button
android:id="#+id/continue_button"
style="#style/LongButton"
android:text="Continue"
android:layout_alignParentBottom="true"/>
When we first open up the activity, the button should be shown at the bottom, therefore, I used:
android:layout_alignParentBottom="true"
As soon as the EditText gains focus and the keyboard pops-up, everything should scroll up leaving me enough space to write. But what I'm getting is this:
As you can see in the image, the cursor hides behind the button. What I want is a little bit of space between edittext and the button. Using margins didn't help.
Try using this android:layout_above property of relative layout you can align the layout above other layout or android:layout_below with your button if button is also part of relative layout.
I'm using scrollview to scroll my view up when soft keyboard open. But it's make more than required space between button and keyboard.
Can we remove this large space.
Here is my xml code block.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/searchBtn"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="20dp"
android:hint="#string/search_hint"
android:inputType="number"
android:maxLength="10" />
<Button
android:id="#+id/searchBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#339933"
android:padding="20dp"
android:text="#string/search_button_text"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
To align the click button with the software keyboard, it should be at the layouts bottom.
You should have the click button within the root layout, which should have the click button aligned to bottom, either with linearlayouts gravity or relativelayouts layout_alignParentBottom
So basically you define the layout as follows:
<RelativeLayout>
<Button
android:layout_alignParentBottom="true">
</Button>
</RelativeLayout>
And ta-da! the button is right on top of the software keyboard!
The real problem..
As it turns out in the comments the real problem here is to align the button to the keyboard only when it is visible, which can simply be achieved by having two invidual buttons that visibilitys are toggled based on the keyboard state
So first we define a layout that has two buttons, one for the software keyboard state and one for the "regular" state
<RelativeLayout>
<ScrollView>
<LinearLayout>
<!-- ...... -->
<Button
android:id="#+id/regular_button">
</Button>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/keyboard_aligned_button"
android:layout_alignParentBottom="true">
</Button>
</RelativeLayout>
and now we just hook the keyboard state to the visibility of the buttons, so we need in some way to keep track of the keyboard state, which is explained in many places
and when the keyboard is set to be visible we setVisibility of the regular button to be GONE, and keyboard aligned button to VISIBLE.
After a keyboard is gone visibilities are inversed
I have an EditText inside a LinearLayout which resides inside a ScrollView. Underneath the EditText are a bunch of TextViews to fill up the screen (and beyond). The EditText has a layout_height of 100dp so that it has room for a few lines of text.
Now when i start typing in the EditText and hit "enter" to add a new line after a couple of lines the entire layout (including the ScrollView) start to pan to the top until the entire EditText is not visible anymore.
Apparently the "panning" towards the top starts when the "virtual" height of text inside the EditText (the View bounds remain 100dp high) reaches a certain threshold.
On the activity i have set android:windowSoftInputMode="adjustPan" but a similar problem occurs with adjustResize.
I have also tried to play around with the android:isScrollContainer="false" on the ScrollView or the various min and max properties on the EditText but nothing did help
Here is the layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="Hallo World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:text="I am an EditText"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="top|start" />
<TextView
android:text="Hallo World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Hallo World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
... many more text views ...
</LinearLayout>
</ScrollView>
Does anybody know how i could prevent the entire layout from panning upward when entering text with new lines into the EditText?
I have a layout like:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:layout_weight="1">
<-- A relative layout that contains a lot of edit text fields and a few text views at the bottom that cover up the screen-->
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="something"
android:layout_weight="0"
android:visibility="gone"/>
</LinearLayout>
and what i want to do is just achieve the effect that when the keyboard pops up from tapping on any EditView inside the ScrollView, the button at the bottom should NOT cover up any text views, because it is in the gone state. but right now, whenever i tap on any of the EditText fields, it seems to be covering up some of the text views that i have.
why is the screen rendered such that it designates space for the gone button i have at the bottom?
Try adding the following to the activity tag in your manifest.
android:windowSoftInputMode="adjustNothing"