Android Title bar gets pushed up when edit text content increases - android

I have a relative layout which contains only the edit text view. But when content of edittext increases, my title bar gets shifted upwards. Most of the solutions I went through addresses the issue of shifting title bar when keyboard pops out. But I didn't found anything in case its content increases. I also used android:isScrollContainer="false" as suggested in this post How to avoid soft keyboard pushing up my layout?, but still the same issue. Is there a way to prevent it? Here is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false"
android:background="#drawable/background" >
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:singleLine="false"
android:paddingLeft="10sp"
android:paddingTop="5sp"
android:paddingRight="5sp"
android:scrollbars="vertical"
android:background="#android:color/transparent"
android:textSize="26sp" >
</EditText>
</RelativeLayout>

I managed to solve this issue by putting edittext in scrollview and replacing adjustPan with adjustSize in the manifest. This is the final working layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:paddingLeft="10sp"
android:paddingRight="5sp"
android:paddingTop="5sp"
android:singleLine="false"
android:textSize="25sp" >
</EditText>
</ScrollView>

try to run your code after removing :
android:background="#android:color/transparent"

make your relative layout height and width to wrap_content.......... probably works. since when text increases your complete layout shifts. Try it and please rpy

Usually this can be solved by adding the android:windowSoftInputMode="adjustPan" property to your activity in the AndroidManifest file.

Related

DialogFragment containing a ListView with EditText- focus wont popup keyboard

Im having difficulty to understand the unique behavior I found.
I have a layout with only a ListView, where its item layout is some texts & editText.
Showing such a dialog onscreen leads to an unexpected behavior - keyboard wont pop-up when giving focus to it.
I strangely find that if I add another element to the dialog's layout, the issue is solved.
Dialog layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/listView"
/>
<!-- patch. otherwise, EditText within listview wont pop keyboard. weird, right? -->
<EditText
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content" />
</LinearLayout>
Item layout:
..
...
....
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="5"
android:maxEms="5"
android:editable="true"
android:numeric="integer"
android:id="#+id/purchaseAmount" />
....
...
..
Can anyone give an explanation to that behavior?
Perhaps the ListView does not have focus. You can ensure this by modifying your xml slightly.
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/listView">
<requestFocus/>
</ListView>

how to fix a bottom relative layout when soft keyboard comes?

When i write something on the edit text in my app ,the soft keyboard comes in along with a bottom relative layout..I want to fix the bottom relative layout position fixed.Any help will be greatly appreciated..
I'm guessing Padma Kumar meant android:windowSoftInputMode="adjustNothing" on your manifest activity tag.
add this in your activity tag in manifest.xml file
android:softinputmode="adjustNothing"
Make a fake layout with any height value, then reference it:
<RelativeLayout
android:id="#+id/rl_fake"
android:layout_width="fill_parent"
android:layout_height="320dp" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_main_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
...
</RelativeLayout>
...
<RelativeLayout
android:id="#+id/rl_problem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/rl_fake" >
...
</RelativeLayout>
In Relative layout paste the following code
<LinearLayout
android:id="#+id/ll_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginTop="#dimen/_16dp">
<Button
android:id="#+id/btn_continue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:text="#string/conti"
android:padding="#dimen/_8dp"
android:textColor="#color/white"
android:textSize="#dimen/_16sp" />
</LinearLayout>

Android EditText Layout like Gmail Compose Screen

I am trying to implement the following:
Please check the image here:
The problem is whenever the user taps the compose mail edittext field, the send/save/discard buttons are hidden by the softkeyboard.
Any ideas on how to make those buttons always visible?
Thanks.
[EDIT]
Finally got it solved!Had to use Linearlayout instead of RelativeLayout and assigning proper layout_weight parameter did the trick. Thanks a lot Femi for pointing out that the buttons need to be outside of the ScrollView.
Here is the final working layout xml in case anyone finds it helpful:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"><ScrollView android:layout_alignParentTop="true"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<EditText
android:id="#+id/editTextCompose"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:gravity="top"
android:singleLine="false" android:lines="5"
android:inputType="text"
android:layout_below="#+id/editTextSubject"
>
</EditText>
</RelativeLayout>
</ScrollView><TableLayout android:id="#+id/recipeButtons"
android:background="#B0B0B0" android:padding="3dip"
android:stretchColumns="0,1" android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow android:gravity="center">
<Button android:id="#+id/editOtherAdditionButton"
android:text="Save" />
<Button android:id="#+id/removeOtherAdditionButton"
android:text="Delete" />
</TableRow>
</TableLayout></LinearLayout>
As documented in #mayra's answer to Android soft keyboard covers edittext field you should see http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft for the details to control.
Modifying the Activity's entry in the AndroidManifest to adjustResize should I think do it.
There is another question about this here, but it looks like the best approach is using the windowSoftInputMode

EditText in scroll view in android

I try to create a from application, in the app I have a lengthy form which I want to be in a scroll view, But when I add EditText to the scrollView ..the eclipse shows some error in its designer view.
error!
IllegalStateException: ScrollView can host only one direct child
Exception details are logged in Window > Show View > Error Log
Any one have an idea to crack it out?
I have included this code after getting a solution for the above trouble..!
Now the EditText is not showing any typed text, it just gives some suggestions...!
I have the following XML :
<ScrollView
android:id="#+id/widget64"
android:layout_width="320px"
android:layout_height="358px"
android:fillViewport="true"
android:isScrollContainer="true"
android:saveEnabled="true">
<TableLayout
android:id="#+id/widget58"
android:layout_width="320px"
android:layout_height="65px"
android:orientation="vertical"
>
<TableRow
android:id="#+id/widget60"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/user"
android:text="User"
android:textColor="#000000">
</TextView>
</TableRow>
<TableRow
android:id="#+id/widget60"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<EditText
android:id="#+id/users_first_name"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:hint="First Name"
android:focusable="true"
android:inputType="textPersonName"
android:enabled="true"
android:ems="15">
</EditText>
</TableRow>
</TableLayout>
</ScrollView>
Found the trouble.....
My emulator key was set to Chinese instead of English...
First add any layout to that scrollview and then add edittext to that layout.Then automatically u got the scrolling for that edittext .For Ex:add Linearlayout to that scrollview and then add editText to taht linearlayout.
Yes, ScrollVew can have only one child.
For this do something like this
<ScrollView
fillViewPortView = "true">
<RelativeLayout>
// Design the entire layout in here
// Put your elements one below the other. It will automatically scroll
// dont forget to setFillViewPort view to true in ScrollView
</RelativeLayout>
</ScrollView>
This will solve the problem for sure
Hope his help : )

SoftKeyboard hiding EditText

I have a layout that uses an EditText to let users search a database and populate a ListView. The EditText is about 2/3 of the way from the top of the screen (positioned over an ImageView, and followed by some intro text.)
The problem is that the soft keyboard hides the EditText, so the user can't see what he's typing. (I disabled the auto-suggest.)
I've tried LinearLayout, RelativeLayout, paddings, and different alignments/centerings, but I still can't get it to work right. The EditText is either hidden, gets pushed off the top of the screen, or get "squished" and distorted.
Suggestions???
One possible workaround is to move the EditText to the top of the screen. However, this deviates from the graphic design that I was given.
Another possible workaround is for me to make the soft keyboard open in full screen (not sure how, though). This will still hide the EditText, but then I can re-enable the auto-suggestion so the user can see what he's typing... sort of... because he can only see the suggestions for what he's typing.
Here's my latest attempt. See "introFrame".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/titleContainer"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="#string/title_string"
android:textSize="15sp" android:textColor="#FFFFFF"
android:textStyle="bold" android:paddingLeft="5dp"
android:layout_height="fill_parent" android:layout_width="wrap_content" />
</LinearLayout>
<FrameLayout
android:id="#+id/introFrame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:src="#drawable/main_search_image"
android:scaleType="center"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="140dp" >
<LinearLayout android:id="#+id/introSearchContainer"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<EditText android:id="#+id/intro_search_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" Enter keyword "
android:imeOptions="actionGo"
android:inputType="textFilter"
android:maxLines="1" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="#+id/intro_search_button"
android:background="#drawable/custom_button_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="#string/search_intro"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
</FrameLayout>
<LinearLayout android:id="#+id/listContainer"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/itemlist" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:cacheColorHint="#00000000" />
<TextView android:text="No data found" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center"
android:textSize="16sp" android:textColor="#FFFFFF" android:id="#+id/android:empty" />
</LinearLayout>
</LinearLayout>
What you're looking for is the Activity's windowSoftInputMode attribute. You set this in your AndroidManifest.xml file, and give it a value such as:
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."
adjustResize will probably work for you, as long as you wrap the layout in a ScrollView. It may have negative effects if you have a bitmap image in the background, as it will be resized as well, in which case you may want to use adjustPan instead.
<activity android:windowSoftInputMode="adjustResize" />
or
<activity android:windowSoftInputMode="adjustPan" />
More information is available at the above link.
What has worked for me is to drop my highest-level LinearLayout in a scrollView (the ScrollView can only have one child). This allowed the entire activity/form to scroll up and not clutter the EditText in focus.
First, I set in my activity:
<activity android:windowSoftInputMode="adjustPan" />
Then I did the ScrollView thing I'm talking about:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- STUFF -->
</LinearLayout>
</ScrollView>
just use following in manifest...
<activity
android:windowSoftInputMode="adjustPan">
try giving the edit text a layout_weight (i.e. layout_weight=1) , this may have some other effects on your other layout items that you may have to work through, but this may help it stay visible when soft keyboard pops up

Categories

Resources