Button alignment just below a multi-line EditText - android

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.

Related

Scrollable vertically and horizontally EditText that doesn't automatically break text to the next line

I need an activity that look like a simple text editor: full-screen EditText with submit button below it.
Important:
1. EditText has to scroll both vertically and horizontally
2. Input text goes to the next line ONLY when the user clicks nextline button
3. EditText fills the whole space between the top of the screen and the button
My code:
<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:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<EditText
android:id="#+id/some_edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|left"
/>
</HorizontalScrollView>
</ScrollView>
<Button
android:id="#+id/submit_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"/>
</LinearLayout>
Why bad:
EditText AUTOMATICALLY breaks text to the next line as it reaches the end of the row
It worked fine before I set fillViewport to true. But otherwise EditText doesn't fill entire screen
Thanks in advance
EditText actually has scrolling already built in, so you don't have to use a ScrollView. The only thing is that it doesn't support flings.
<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:orientation="vertical">
<EditText
android:id="#+id/some_edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|left"
/>
<Button
android:id="#+id/submit_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"/>
</LinearLayout>
To stop the automatic wrapping, you can activate horizontal scrolling:
EditText editText = (EditText) findViewById(R.id.some_edittext);
editText.setHorizontallyScrolling(true);
editText.setMovementMethod(new ScrollingMovementMethod());
I think you could set your EditText attribute android:maxLines="1" initially.
And when "new line" button is clicked, you can increase that value programmatically using setMaxLines(int) method.
EditText.setMaxLines(int)
here's the doc -> link
Hope this helped.

Android Soft Keyboard not showing all `EditText`

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?

Android EditText in ScrollView pans to the top when more text is inserted

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?

focusing EditText on HorizontalScrollView causes ScrollView to hide EditText

I have a horizontal scroll view that takes up the right half of the screen. On it, I have an EditText. When I select the EditText to edit the text, the HorizontalScrollView scrolls to the right. I'm guessing it's trying to place the EditText to the leftmost position. Regardless, since the HorizontalScrollView takes up the rightside of the screen, by doing this, I can no longer see the EditText since its now covered up by the contents I put on the left side of the screen. How can I prevent HorizontalScrollView from automatically scrolling when I focus on something inside its layout?
Thanks. Much appreciated.
halp
Edit: Posting code. I'm actually creating my EditText's based off of generated info, so this is not what it actually looks like, but it should capture the ideai.
<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" >
<View
android:layout_leftOf="#+id/Anchor"/>
<View
android:id="#+id/Anchor"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true"
android:background="#000" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rightOf="#+id/Anchor"
android:fillViewport="true" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp" >
<TableRow>
<EditText>
ABOVE is the view that is going to the left
MOre views which would cause Scrolling to the right
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
try this in XML the EditText if use
android:gravity="center"
remove it

Why does the visibility "gone" for button not work with scrollviews?

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"

Categories

Resources