android EditText 输入文本时滞后
我正在开发某种聊天应用程序,一切都很顺利,但我遇到了一个问题。 EditText 滞后,每当我在 edittext 中输入一些字母时,我的 Android 键盘都会在第二或某些时候冻结。 O 真的不知道要提供什么代码,因为它只是一个简单的 EditText 框。这是我的制作方法:
linforbutton.add(new LinearLayout(this)); //linear layout on the bottom os creen for edittext and button
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
linforbutton.get(x).setLayoutParams(params);
linforbutton.get(x).setBackgroundColor(0xff426193);
linforbutton.get(x).setOrientation(LinearLayout.HORIZONTAL);
int padding_in_dp1 = 3;
final float scale1 = getResources().getDisplayMetrics().density;
int padding_in_px1 = (int) (padding_in_dp1 * scale1 + 0.5f);
linforbutton.get(x).setPadding(0, 0, 0, 0);
relmsg.get(x).addView(linforbutton.get(x));
msginput.add(new EditText(this));
msginput.get(x).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
msginput.get(x).setMaxLines(3);
msginput.get(x).setMinLines(1);
msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
msginput.get(x).setImeOptions(EditorInfo.IME_ACTION_SEND);
msginput.get(x).setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
linforbutton.get(x).addView(msginput.get(x));
btninput.add(new Button(this));
btninput.get(x).setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btninput.get(x).setText("Отпр.");
int padding_in_dp2 = 20;
final float scale2 = getResources().getDisplayMetrics().density;
int padding_in_px2 = (int) (padding_in_dp2 * scale2 + 0.5f);
btninput.get(x).setPadding(padding_in_px2, 0, padding_in_px2, 0);
linforbutton.get(x).addView(btninput.get(x));
我制作了一些视图,所以我有一个 for 循环,不看数组。我尝试删除数组并仅使一个视图一个编辑文本一个按钮,但它不起作用。
Im developing some sort of chat application, all goes wellm but im stuck with one problem.
EditText lags, my android keyboard gets freezed on second or some whenever I type some letter in edittext. O din't really know what code to provide, because it's just a simple EditText box. Here's how i make it:
linforbutton.add(new LinearLayout(this)); //linear layout on the bottom os creen for edittext and button
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
linforbutton.get(x).setLayoutParams(params);
linforbutton.get(x).setBackgroundColor(0xff426193);
linforbutton.get(x).setOrientation(LinearLayout.HORIZONTAL);
int padding_in_dp1 = 3;
final float scale1 = getResources().getDisplayMetrics().density;
int padding_in_px1 = (int) (padding_in_dp1 * scale1 + 0.5f);
linforbutton.get(x).setPadding(0, 0, 0, 0);
relmsg.get(x).addView(linforbutton.get(x));
msginput.add(new EditText(this));
msginput.get(x).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
msginput.get(x).setMaxLines(3);
msginput.get(x).setMinLines(1);
msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
msginput.get(x).setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
msginput.get(x).setImeOptions(EditorInfo.IME_ACTION_SEND);
msginput.get(x).setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
linforbutton.get(x).addView(msginput.get(x));
btninput.add(new Button(this));
btninput.get(x).setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btninput.get(x).setText("Отпр.");
int padding_in_dp2 = 20;
final float scale2 = getResources().getDisplayMetrics().density;
int padding_in_px2 = (int) (padding_in_dp2 * scale2 + 0.5f);
btninput.get(x).setPadding(padding_in_px2, 0, padding_in_px2, 0);
linforbutton.get(x).addView(btninput.get(x));
Im making some views so i have a for loop, dont look at the arrays. I tried removing arrays and making only one view one edittext one button and it didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以看起来你的线程可能会相互冲突。环顾一下你的事件监听器,也许其中一个保存着进程。不久前,我的 GPS 监听器 (onLocationChanged) 遇到了这个问题。
我从这个监听器将数据发布到服务器,它刚刚杀死了应用程序。将代码块移至新线程后,它解决了我的问题。
So it seems that your threads may conflict with each other. Look around your event listeners, maybe one of them holds the process. I had this problem a while ago with my GPS listeners (onLocationChanged).
I posted the data to the server from this listener and it just killed the application. After moving that block of code to a new thread it solved my problem.