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
Related
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've read several discussions around this issue and it has to do with the android:windowSoftInputMode="stateHidden|adjustResize" (as well as adjustPan) of the manifest file when attempting to get a ScrollView of a LinearLayout to adjust when the keyboard is shown.
I have a layout that has a LinearLayout inside of a ScrollView that contains 10 LinearLayout sections (TextView/EditText views). I have tried every combination I have read about and no matter what, when the keyboard is opened as a result of clicking on the top EditText, the view is adjusted (panned) such that the top field is behind the action bar. I can scroll to the bottom of the page, but I can't get to the top EditText - I can only scroll to the 2nd one. I can try and pull down and I can start to see the top EditText but can't get it to show unless I dismiss the keyboard (which obviously I can't edit the text then).
<ScrollView
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"
tools:context="com.example.myproject.FirstActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
tools:showIn="#layout/activity_work"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="x1"
android:layout_weight="50"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/work_one"
android:hint="0"
android:gravity="right"
android:selectAllOnFocus="true"
android:textAlignment="gravity"
android:layout_weight="50" />
</LinearLayout>
.
. (9 more of these)
.
</LinearLayout>
</ScrollView>
UPDATE:
so I tried: android:windowSoftInputMode="adjustResize" and / or android:windowSoftInputMode="adjustPan" and the soft keyboard shifts the top fields under the action bar.
Thoughts?
Try either android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustPan"
From the doc
"adjustResize"
The activity's main window is always resized to make room for the soft keyboard on screen.
"adjustPan"
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
I copied the answer from this Stack Overflow answer
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?
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"