howerknea
howerknea

Reputation: 375

About ViewGroup.requestLayout()

I have a custom viewGroup like this

public class CustomLinearLayout extends LinearLayout {
public CustomLinearLayout(Context context) {
    super(context);
}

public CustomLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected void onWindowVisibilityChanged(int visibility) {
    super.onWindowVisibilityChanged(visibility);
    requestLayout();
    System.out.println("right after request layout");
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    System.out.println("on layout");
}

}

When i run this app,i found the log like this : enter image description here How could this happen ? the onLayout() runs after the System.out.println("right after request layout");。 Could anybody tell me why?

Upvotes: 1

Views: 530

Answers (1)

Henry
Henry

Reputation: 17841

From the documentation here: http://developer.android.com/reference/android/view/View.html#requestLayout()

"Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree."

The requestLayout() call only schedules a layout pass, but does not do it immediately.

Upvotes: 1

Related Questions