Android: programmatically adjust ConstraintLayout’s layout constraint tip.
As great as Android’s dp unit and ConstraintLayout are, sometimes adjusting View objects placement dynamically just offer more flexibility.
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) button.getLayoutParams(); // "layout_constraintStart_toStartOf" unset params.startToStart = -1; // "layout_constraintEnd_toEndOf" set to parent params.endToEnd = 0; // "layout_constraintBottom_toTopOf" set to other View object params.bottomToTop = R.id.other_button;
Check screen density: getting the screen density programmatically in android?
For complex UI, I have seem people use two xml for one activity. One xml for smaller screens, and one for bigger screens. Pro is you don’t have to programmatically adjust size, constraints and margins. Con is you end up maintaining two xml, where you can use xml
include tag to cut repetition. Not too bad at all.