How to set layout property from code
11,738
You need to use RelativeLayout.LayoutParams for the textview and then use addRule.
Example:
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
params.addRule(RelativeLayout.LAYOUT_ABOVE, R.id.flag_left);
tv.setLayoutParams(params);
Author by
Dijo David
I m a Tech fanatic.. Loves computers. Writes codes. Spend life in Web!! ;)
Updated on June 05, 2022Comments
-
Dijo David almost 2 years
How can I set the property of an TextView which comes under a RelativeLayout from the code.
Here s my layout:
<RelativeLayout android:id="@+id/team_left" android:layout_width="wrap_content" android:layout_height="50dip" android:layout_alignParentLeft="true"> <ImageView android:id="@+id/flag_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/img"/> <TextView android:id="@+id/country_left" android:textColor="@color/txt_color" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout>
How can I set the properties like "android:layout_toRightOf="@id/flag_left" for the textview from the code.