MotionLayout之ConstraintSet动态修改参数

根据我几分钟的经验来跟大家交流下哈!
设置一下代码时无效的

 MotionLayout motionLayout;
    private ConstraintSet set;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_motion_topbar);
        motionLayout = findViewById(R.id.motionlayout_root);
        set = motionLayout.getConstraintSet(R.id.expanded);
        set.constrainHeight(R.id.toolbar_image,170);
        set.applyTo(motionLayout);



    }

这样设置才是有效的,记住要克隆,克隆

MotionLayout motionLayout;
    private ConstraintSet set;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_motion_topbar);
        set = new ConstraintSet();
        motionLayout = findViewById(R.id.motionlayout_root);
        set.clone( motionLayout.getConstraintSet(R.id.expanded));
        set.constrainHeight(R.id.toolbar_image,170);
        set.applyTo(motionLayout);


    }

 

你可能感兴趣的:(MotionLayout之ConstraintSet动态修改参数)