使用setLayoutParams时出现无限循环

时间:2019-03-31 18:00:21

标签: android android-collapsingtoolbarlayout

我尝试在CoordinatorLayout.Behavior类的onDependentViewChanged方法中更改View的大小。但是,当我使用setLayoutParams方法时,就会开始无限循环(我在日志中检查了此情况)。

public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {

    AppBarLayout appBarLayout = (AppBarLayout) dependency;


    int left = 10;
    int top = 10;
    int width = 10;
    int height = 10;


    child.setX(left);
    child.setY(top);
    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();

    //set new size of view

    lp.width = width;
    lp.height = height;
    child.setLayoutParams(lp);


    return true;
}

0 个答案:

没有答案