Trace: requestLayout() improperly called?
23,054
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 -> ...
Related videos on Youtube
Comments
-
Aashir almost 2 years
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 #7f060066 app:id/normal_image} during second layout pass: posting in next frame
Here is the code for TopCenterImageView:
public class TopCenterImageView extends ImageView { public TopCenterImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setScaleType(ScaleType.MATRIX); } public TopCenterImageView(Context context, AttributeSet attrs) { super(context, attrs); setScaleType(ScaleType.MATRIX); } public TopCenterImageView(Context context) { super(context); setScaleType(ScaleType.MATRIX); } @Override protected boolean setFrame(int l, int t, int r, int b) { if (getDrawable() == null) { return super.setFrame(l, t, r, b); } Matrix matrix = getImageMatrix(); float scaleFactor = getWidth() / (float) getDrawable().getIntrinsicWidth(); matrix.setScale(scaleFactor, scaleFactor, 0, 0); setImageMatrix(matrix); return super.setFrame(l, t, r, b); } }
-
Kai over 10 yearsI just encountered the same issue today and it appears that the View in the log is not the culprit. Do you happen to use ValueAnimator or another Animator class in your code?
-
Aashir over 10 yearsI don't. All the code simply does is that it fetches an image, blurs it and places it over the original while setting the alpha as the user scrolls.
-
Kai over 10 yearsHmm... if it's still a problem for you, I guess the only thing left to do is to check UI-thread related code. The problem with my code was that I had called
ValueAnimator.start()
multiple times in rapid succession. And the strangest thing is that I would still see the "requestLayout() improperly called..." error even when I removed any UI related code from ValueAnimator. Oh and it seem to only happen on 4.3 devices as well. -
Aashir over 10 yearsI only setAlpha to an overlay image. Oh and I had been testing on a 4.3 device. Ill check it out on another.
-
Kai over 10 yearsDo you do that periodically? If so maybe try commenting out all related code and see if the issue persists.
-
Aashir about 10 yearsI did, it still persists. Been debugging but can't find the source.
-
Daniel Bo about 10 yearsI assume that
super.setFrame(l, t, r, b);
callsrequestLayout()
somewhere. Is there a chance you are using setFrame in an asynctask? -
alanv about 10 yearsCalling setScaleType() calls requestLayout(), which would be "improper" during a layout pass. You might see this during a layout pass that creates new views, such as a ListView layout. You don't need to worry too much about this though, as it just schedules another layout pass.
-
-
Robert P over 6 yearsIn a custom
TableLayout
class I created I had the same issue. It did not just show the warning, but also prevented scrolling, if aEditText
inside myTableLayout
had the focus. Movingsupoer.onLayout
to the bottom of myonLayout
method solved it. +1