Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically set "Layout to right of" property in android

Tags:

android

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.

like image 293
Maneesh Avatar asked Jun 12 '10 09:06

Maneesh


2 Answers

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()); 
like image 141
notmystyle Avatar answered Oct 11 '22 08:10

notmystyle


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); 
like image 27
Amir Hossein Ghasemi Avatar answered Oct 11 '22 10:10

Amir Hossein Ghasemi