The first time i focus an edittext view i notice a lag of one or two seconds before i can write anything in the textbox.
I notice this behavior even on an app without any code more than what's nessecary to initialize the application.
What am i doing wrong?
I've INSTANTLY fixed this issue for me; I saw in the DDMS that a lot of redraw's and recalculations were occurring while entering text, and a lot of info about RelativeLayouts were being called. So, I checked my layout; i had some Multi-Line EditText's who were direct children of a RelativeLayout. So, I wrapped those up into a Linear Layout, and specified my desired width/height at the LinearLayout, not each EditText.
Guess what? It totally fixed it!!
(below, some code... keep in mind, this is just an approximation. Don't try and copy/paste)
BEFORE:
<RelativeLayout>
<EditText
android:layout_width="wrap_content" />
<EditText
android:layout_width="wrap_content" />
</RelativeLayout>
AFTER:
<RelativeLayout>
<LinearLayout
android:layout_width="wrap_content" >
<EditText
android:layout_width="fill_parent" />
<EditText
android:layout_width="fill_parent" />
</LinearLayout>
</RelativeLayout>
Wrapped my EditText's into a LinearLayout, and relinquished dynamic layout controls to the LinearLayout.
It was an amazing and instant improvement.
Are you using the emulator?
This is common when you are using the emulator regardless of debug mode or not...at least from my (limited) experience so far. Try your app out on a real phone and see what happens.
I turned off USB debugging and uninstalled a few keyboards. Seems to work fine now. Thanks all.
Edit AndroidManifest:
My old code
< uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
My new code
< uses-sdk android:minSdkVersion="8" />
I just removed the targetSdkVersion and the lag went away.
In my case the symptoms were the same, a delay occurred to present the keyboard and when typing the letters were gradually appearing.
The solution is because I had put a Background image in the RelativeLayout, when I did a test taking the background worked out and stopped the delay, so I entered an online site that reduces photos and then reduced from 93kb to 50kb and worked perfectly.
In my case the problem was the background-drawable for the activity (as dialog) on XML, it was too heavy. changing it, works fine.
In my case, the lag was because of the heavy serialised objects I used to pass in Intent putExtra() of activities in the app. Those would continue to stay in the memory and cause the problem.
Related
I have an EditText and a custom keyboard, so i want to avoid softkeyboard to popping up. It must never pop up, but i need also to leave EditText focusable to use cursor. Simple as it is but so hard to accomplish.
I already tried a lot of solutions but they aren't working and since they are outdated i'm asking now for an actual working way. Solutions targetted as API 11 are such useless now since they don't work, already tried. I'd love to listen for suggestions from people who already tried the method on recent versions, such as Lollipop (API 21-22) or Marshmallow (23). I can't believe that there is no workaround, and i'm getting mad
This will help you
editText.setInputType(InputType.TYPE_NULL);
In your layout file add these line
android:descendantFocusability="beforeDescendants" and
android:focusableInTouchMode="true"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</EditText>
</RelativeLayout>
In your Activity class add this line
this.getWindow().
setSoftInputMode
(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
I have the following problem, and I cannot figure out how to eve try solving it (or whether there is a way):
My problem
I have SrollView, containing to EditText input fields. One is a single line, below is a multiline. Everything's fine and works as expected, up until I put too much stuff into the multiline EditText. When I fast scroll the view, the scrolling skips and stutters, very obviously, the whole effect is rather disturbing. tried on a Galaxy S3 with a custom AOSP ROM, and Note 4 with official 5.1.1, no difference at all.
I would expect a very heavy EditText makes it difficult to smoothly redraw on a fling, but this starts happening with relatively short text (approx 4-5 screen-pages long).
Edit: This also seems to happen on a simple scroll, when I do as much as touch it and move it a few lines (scrolling is not near to being smooth, that is)
The setup
I have reduced the widgets to the bare minimum, even removed padding, only the problem does not improve. From the Java code I also removed anything (any styling, or typeface, anything that affects the widgets at all), still no improvement.
If this is of any significance, the ScrollView in question is inside a fragment, that is one of two pages of a ViewPager. There is nothing else on this fragment ATM.
Here's the XML (as you will see, it's as base as possible):
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:inputType="textMultiLine"/>
</LinearLayout>
</ScrollView>
What I tried
Any advice I found regards only ListViews, and some attributes like android:smoothScrollbar, which have no effect here (I tried them all).
For the record, I did try out of frustration all of the below ( I know most of these has not much to do with ScrollViews, but I'm becoming hopeless here):
android:hardwareAccelerated="true"
android:fastScrollEnabled="true"
android:scrollingCache="true"
android:smoothScrollbar="true"
and also tried setting from the Java code things like
.setSmoothScrollingEnabled(true);
.fling(3500);
still no luck.
Question recap
Is there any way to make a simple widget like this scroll smoothly at all?
Thanks for your time if you've read through and even more if you answer. :)
I am a first time developer for Android, so you can say I've been learning as I was developing. For most of my code that doesn't have to do with the XML layout, I had no problem patching my rookie mistakes. With that said, my rookie mistakes has caught up to me in regards to two TextViews when I initially designed them with the GUI interface designer (my major rookie mistake).
My display_city tv and display_today_date tv seem to have a symbiotic relationship with each other. Removal of either one would crash the app. They seem so dependent on each other that changing each other's positioning is impossible (at least from the myriad of things I have tried such as setting layout margins).
<TextView
android:id="#+id/display_city"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dip"
android:layout_above="#+id/display_today_date"
android:layout_below="#+id/get_data"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" />
<TextView
android:id="#+id/display_today_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/display_pollen_type"/>
My question is - how do I simply position display_today_date immediately after my display_city? When I first started this Android app, I relied a lot on the GUI builder. That was my first rookie mistake, which resulted in this symbiotic relationship I explained.
Currently this is what my app looks like:
I have tried changing display_today_date's layout to android:layout_below="#+id/display_city. This results in a crash. I checked logcat, but it did not give me relevant information to the reason of the crash within the XML file.
P.S. get_data is my TextEdit box.
You already have the city to show above the date with the line android:layout_above="#+id/display_today_date". You can't have 2 views in a relative layout each reference the other, or it won't be able to figure out what to do. If you don't want to put the city above the date, delete that line then add the code to place it where you want.
You could use a LinearLayout with the orientation set to horizontal. That way there is no reference to another view. So if you delete one the other one won't cause the app to crash.
I'm not looking for code, either I won't post any, just an explanation, because I'm kind of lost.
There is this main issue about the resizing when softkeyboard appear.
In my case
I have a listView feeded with 2 editText and many textView with database content using a custom cursorAdapter.
1) AdjustPan
It's pretty simple. When I use the adjustPan property, everything works quite good, except the fact that when I press an editText in my listView and if the listview is bigger than the screensize, I can't scroll. This is actually the normal behaviour and I can understand it.
2) AdjustResize
Here I can scroll as much as I wish.
This property is the one I want to use. But I'm facing 2 issues :
When I press on one of the two editText, I just can't write in. Impossible, even thought it has the focus. I'm forcing the softkeyboard to appear, I try to type some letters in (remember that this editText is focused) but nothing happens.
Again, when I press one of the two editText, it just reorganize (apparently randomly) listview's items. Even thought it's working perfectly with adjustPan, with adjustResize, it's messing with items of the listView.
Any information about one of the 2 issues would be helpful. You can even ask for code, but one more time, I'm just looking for a general explanation that could help. Thanks.
Here this mention issue is same facing me in my app and here some change in my code is this working fine in my app. please try this...
<activity android:name="com.MainActivity"
android:configChanges="orientation|screenSize"/>
<ListView
android:id="#+id/fields_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusableInTouchMode="true"
android:focusable="true"
/>
<EditText
android:id="#+id/input_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="true"
android:gravity="top"
android:inputType="none"
android:textColor="#color/black"/>
When the software keyboard shows, it resizes my layout and thus squeezes the background image together. My question is basically a duplicate of this question, which is explained in a very good way:
Software keyboard resizes background image on Android
However, that question was closed when they found a hack to solve it. I cannot use this hack. My entire layout is inside a ScrollView, and I need to be able to use this scrollview properly at all times. By using android:windowSoftInputMode="stateVisible|adjustPan" the user will not be able to scroll down and see the bottom of the screen while the keyboard is showing, since the layout will partly exist behind the keyboard. Thus the solution is unacceptable to me. Are there any better solutions out there?
Cheers,
I actually ran into a similar problem not too long ago. I stumbled upon the correct answer with a bit of work, though.
In your android manifest for this project, attached to the specific activity that you are using, use the line android:windowSoftInputMode="adjustPan|stateVisible" in the activity tag.
adjustPan basically means that your activity will not resize itself to fit the soft keyboard, and stateVisible means that the soft keyboard will show when requested (this can be stateAlwaysVisible, etc if necessary)
source :
Android Dev for Activity tags
After days of hardcore hacking I finally managed to construct a solution so advanced it might actually hurt to read it. I place an ImageView with the background behind the scrollview, and set scaleType="matrix" so it does not shrink when the keyboard is shown.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/black"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/mah_kewl_background"
android:scaleType="matrix"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<RelativeLayout
android:id="#+id/smsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="PLUNX"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You can use the windowBackground property, which makes the drawable fit the whole screen.
To do that you need to:
1- Create a style:
<style name="Background" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/you_bg_drawable</item>
</style>
2- Set your activity style in the AndroidManifest.xml
<activity
android:name=".ui.your_activity"
android:theme="#style/Background"/>
I was googling for a solution to this exact problem when I came across this, and after doing some research I found a solution I think is slightly better. Instead of hacking with a ImageView you can use this from your activity:
getWindow().setBackgroundDrawableResource(R.drawable.bg_my_background);
Hope it helps anyone else searching for a solution for this.
I can't comment on your answer but I'd like to add something.
I understand your dilemma and why the solution you linked to isn't a complete solution for your situation (since you can't scroll to the bottom of the view). I have a similar situation with a large scrollable EditText box. When the soft keyboard pops up I don't like my background getting squished.
I have tried your solution and while at first glance it appears to work, there are some situations where it might not be ideal:
If you allow your app the have a landscape mode, the background will not resize/stretch
If you run your app on a device with a larger screen or dpi, your background may not fill the screen
Basically it seems that when you set the scaleType to matrix you're telling Android to draw the background 1:1 and not to scale. So what's happening when you open the soft keyboard using your solution is, your scrollView and imageView are all getting resized as usual, but the image src you set remains 1:1 thus continues showing the same area.
So if for example your background image was set to a specific size (e.g. 480 x 800) and it perfectly fills your Nexus One, the moment you rotate to landscape you will have a black area along the right.
This is moot, of course, if your background is simply a repeating pattern, in which case you can make it extremely large and hopefully compensate for various screens (maybe even tablets).
Or you can also supply different backgrounds for different screen sizes/densities/orientations, but this still doesn't account for scaling.
In a vain effort to try and solve this, I stumbled upon a View attribute called android:isScrollContainer. This attribute tells certain views whether or not they are allowed to resize upon display of the soft keyboard. This is also mentioned by someone in your linked solution. I have tried setting this (to false) on the ViewGroup containing my background, but any child element that scrolls seems override it causing the squishing again.
As of right now I don't think there is a complete solution for our situation. Your's definitely works in some instances and I thank you for the effort. Hopefully Google will offer a solution in the future, but I don't think they would consider this a problem/priority.
Maybe there's another (really simple!) solution:
In styles.xml:
create a new style like this:
<style name="Yourstyle" parent="AppBaseTheme">
<item name="android:windowBackground">#drawable/mybackground</item>
</style>
AppBaseTheme is your normally used theme for your app.
Then you add in Manifest.xml:
<activity
android:name="com.your.app.name.Activity"
android:theme="#style/Yourstyle">
</activity>
So you have the same style but with a background.
Important: don't set any backgrounds in your normal .xml file!
It's my first post and I hope it helps and sorry for my English.
in Androidmanifest in activity tag use:
<activity ... android:windowSoftInputMode="adjustPan" ></activity>
check Android Developer reference
How about a solution where the 'background' is a Layout. Can we inflate a layout, make it the entire window size, then insert it as a window background?
After a lot of time searching...
Put android:windowSoftInputMode="adjustPan|stateVisible" in each Activitys