how to MODIFY a constraint layout programmatically?

前端 未结 4 786
离开以前
离开以前 2021-02-18 13:56

Ive got a view like below :

 

        
4条回答
  •  清酒与你
    2021-02-18 14:49

    Here is what I did (no need for ConstraintSet, we can work directly on the constraints themselves):

    ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) myView.getLayoutParams();
    params.horizontalBias = 0.2f; // here is one modification for example. modify anything else you want :)
    myView.setLayoutParams(params); // request the view to use the new modified params
    

    it worked like a charm when I had a SeekBar and a TextView below it (aligned to it both left+right), and I wanted to update the TextView position to be under the SeekBar's cursor, so I had to update the horizontal bias params on the SeekBar's OnSeekBarChangeListener

提交回复
热议问题