I want to set property "Layout to right of" of control at runtime in android. Actually I want to adjust controls when screen changes orientation.
You can do something like this:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.RIGHT_OF, view.getId());
If you define a new LayoutParams
, you lose other rules.
So if you just want to change or add a rule, do this:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams(); params.addRule(RelativeLayout.RIGHT_OF, targetView.getId()); view.setLayoutParams(params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With