Skip to content
Advertisement

Creating Constraint layout uisng java file

I am trying to create constraint layout using Mainactivity.java but I am facing some problems. I’m getting the below output.

enter image description here

The constraint layout isn’t matching the size of parent.

I have created 2 classes 1 is MainActivity.java and another is MyConstraintLayout.Java

MyconstraintLayout.java

JavaScript

MainActivity.java

JavaScript

Don’t have any XML file.

Thank you in advance

Advertisement

Answer

You are calling setLayoutParams() on the ConstraintLayout and not on the child Views that you’ve added to the ConstraintLayout. You should be doing something like this instead:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement