ClearableEditText - requestLayout()在Android 4.3上不正确地调用 [英] ClearableEditText - requestLayout() improperly called on Android 4.3

查看:197
本文介绍了ClearableEditText - requestLayout()在Android 4.3上不正确地调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施了。


I implemented ClearableEdittext and it works perfectly except on 4.3 where the logcat floods me with:

W/View(16611): requestLayout() improperly called by com.[myPackage].ui.widgets.ClearableEditText{42233dd0 VFED..CL .F....ID 0,0-708,88 #7f050127 app:id/SearchEdittext} during layout: running second layout pass
W/View(16611): requestLayout() improperly called by com.[myPackage].ui.widgets.ClearableEditText{42233dd0 VFED..CL .F....ID 0,0-708,88 #7f050127 app:id/SearchEdittext} during layout: running second layout pass
W/View(16611): requestLayout() improperly called by com.[myPackage].ui.widgets.ClearableEditText{42233dd0 VFED..CL .F...... 0,0-708,88 #7f050127 app:id/SearchEdittext} during second layout pass: posting in next frame

and when typing in the edittext no text shows up. Also after this starts flooding the logcat, the UI is getting frozen except the soft keyboard.

Cannot find any info on this on the internetz. AndrequestLayout() must be called inside Edittext/Textview class cause I never call it. Do anyone of you know how to fix this or what is causing the bug?

EDIT1 OK, so the problem goes away if I comment out the line:

setCompoundDrawables(getCompoundDrawables()[0], getCompoundDrawables()[1], x, getCompoundDrawables()[3]);

I tried posting this as a runnable to the view's UI queue but no text shows up.

EDIT2 I have seen this video of an Android Developer explaining that something recursive is happening during onLayout, but once again, I merely subclass EditText.

EDIT3 I also tried discarding the compound drawable and using another ImageView on top of the EditText but it has something to do with the layout passes when drawing something on top of the Edittext I believe... the recursive call is still happening and its blocking the UI. Don't know what to try next... 4.3 sux

EDIT4 I ended up using a linear layout with horizontal orientation and custom 9 patch drawables for the background of the components. In the layout I have a normal edittext with my custom 9patch Bg and then an ImageButton with another custom 9patch Bg.

Something like this:

The red line delimits the Edittext from the ImageButton. It now works on 4.3

解决方案

A bit late respons, but I just had a related issue with the ClearableEditText component.

It seems that, due to the change of compounddrawables in setClearIconVisible(), an eternal loop of onfocus events are triggered.

I changed the setClearIconVisible to only change the drawable if there are any real change.

   protected void setClearIconVisible(boolean visible) {
        boolean wasVisible = getCompoundDrawables()[2] != null;
        if(wasVisible == visible) return;

        setCompoundDrawables(oldDrawables[0], oldDrawables[1], x, oldDrawables[3]);
        setCompoundDrawablePadding(oldPadding);
    }

That fixed my issue with the keyboard not reappearing. An eternal loop of onfocus-events won't do anyone any good. It still adds another round of layout and focusedChanged, so there might be a more clever solution to this. I'm fine with one extra round, tho.

I've also sent a pull request to the developer, https://github.com/yanchenko/droidparts/pull/31.

这篇关于ClearableEditText - requestLayout()在Android 4.3上不正确地调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆