gpt4 book ai didi

android - 关于 ViewGroup.requestLayout()

转载 作者:行者123 更新时间:2023-11-30 01:49:53 24 4
gpt4 key购买 nike

我有一个像这样的自定义viewGroup

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");
}

当我运行这个应用程序时,我发现了这样的日志: enter image description here怎么会这样? onLayout()System.out.println("right after request layout"); 之后运行。谁能告诉我为什么?

最佳答案

来自此处的文档: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."

requestLayout() 调用仅安排布局传递,但不会立即执行。

关于android - 关于 ViewGroup.requestLayout(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33227494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com