Skip to content Skip to sidebar Skip to footer

Trace: Requestlayout() Improperly Called?

Can anyone tell me how to fix the following trace: W/View (16810): requestLayout() improperly called by theme.effects.TopCenterImageView{41dc73f0 V.ED.... ........ 0,0-480,690

Solution 1:

As seen here, setScaleType will call requestLayout, but the constructor of ImageView already call it before. So it will cause the layout to have multiple requestLayout called, one during the layout pass. It's just a warning because at a small scale, it's not a problem.

You will find some good research in this thread (not the roboguice part though).

Solution 2:

I changed a child views layout params in the onLayout method AFTER calling super.onLayout(); That lead to a recursion:

Childlayout params changed -> parent view onRequestLayout() -> parent view onLayout -> childview params changed -> ...

Solution 3:

SOLUTION:


Use changed parameter as a change check.

overridefunonLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
    super.onLayout(changed, left, top, right, bottom)
    Log.i(TAG, "onLayout: $changed")
    if (changed) {
        changeDefaultView(size)
    }
}

changed is equal to:

TRUE - when the layout CHANGED in comparison with the previous.

FALSE - when the layout DID NOT change in comparison with the previous.

Post a Comment for "Trace: Requestlayout() Improperly Called?"