Edittext “lag” android

不羁岁月 提交于 2019-12-08 00:21:18

问题


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?


回答1:


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.




回答2:


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.




回答3:


I turned off USB debugging and uninstalled a few keyboards. Seems to work fine now. Thanks all.




回答4:


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.




回答5:


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.




回答6:


In my case the problem was the background-drawable for the activity (as dialog) on XML, it was too heavy. changing it, works fine.



来源:https://stackoverflow.com/questions/4069855/edittext-lag-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!