Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set layout_toEndOf and layout_toRightOf programmatically in textview

Tags:

android

I want set these attribute programmatically :-

android:layout_toEndOf="@+id/imageView1"
android:layout_toRightOf="@+id/imageView1"
like image 695
om_jaipur Avatar asked Dec 02 '22 15:12

om_jaipur


1 Answers

The parent of the View has to be a RelativeLayout of course. Then you can do

 final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
 params.addRule(RelativeLayout.RIGHT_OF, R.id.imageView1);
 params.addRule(RelativeLayout.END_OF, R.id.imageView1);

and call

view.setLayoutParams(params);
like image 86
Blackbelt Avatar answered Jan 30 '23 07:01

Blackbelt